Learning VBA

Vin90

New Member
Joined
Oct 20, 2017
Messages
29
Hi guys,

I'm currently working & learning to play with VBA and create certain command button and userforms to ease some of the job.

So I've been working on this forms and get stuck with "Compile Error: Method or data member not found"

The idea is to have 1 command button on the 1st userform which will prompt the 2nd userform, and on the 2nd userform there are two command buttons (cmdY - Yes, cmdN - No).

I've get the first part of the form working properly, but when I get the aforementioned error when I click on the cmd1 button.

Here is how I code:

Userform 1:
Code:
Private Sub UserForm_Initialize()
[COLOR=#008000]    'Populate control.
[/COLOR]    With cboShift
        .AddItem "Night"
        .AddItem "Morning"
        .AddItem "Evening"
    End With
    With cboPrd
        .AddItem "K2"
        .AddItem "TC"
        .AddItem "TP"
    End With
    txtDate.Value = Format(Date, "mm/dd/yyyy")
    Label1100.Font.Size = 15
    Label1100.Font.Bold = True
    Label1200.Font.Size = 14
    Label1200.Font.Bold = True
    Label1300.Font.Size = 14
    Label1300.Font.Bold = True
    Label1301.Font.Size = 10
    Label1301.Font.Bold = True
    Label1302.Font.Size = 10
    Label1302.Font.Bold = True
    Label1400.Font.Size = 14
    Label1400.Font.Bold = True
End Sub

Private Sub cmdAdd_Click()
[COLOR=#008000]    'show formW.
[/COLOR]    formW.Show
End Sub

Private Sub cmdClose_Click()
[COLOR=#008000]    'Close UserForm.
[/COLOR]    Unload Me
End Sub


Userform 2
Code:
Private Sub cmdY_Click()
[COLOR=#008000]    'Copy input values to sheet.
[/COLOR]    Dim lRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Data")
    lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    With ws
        .Cells(lRow, 1).Value = Me.txtDate.Value
        .Cells(lRow, 3).Value = Me.cboShift.Value
        .Cells(lRow, 4).Value = Me.cboPrd.Value
        .Cells(lRow, 5).Value = Me.txtTB.Value
        .Cells(lRow, 6).Value = Me.txtGP.Value
        .Cells(lRow, 7).Value = Me.txtTR.Value
        .Cells(lRow, 8).Value = Me.txtcap.Value
        .Cells(lRow, 9).Value = Me.txtcap5.Value
        .Cells(lRow, 10).Value = Me.txtbl.Value
        .Cells(lRow, 11).Value = Me.txtbl5.Value
        .Cells(lRow, 12).Value = Me.txtblsp.Value
        .Cells(lRow, 13).Value = Me.txtblsp5.Value
        .Cells(lRow, 14).Value = Me.txtnl.Value
        .Cells(lRow, 15).Value = Me.txtnl5.Value
        .Cells(lRow, 16).Value = Me.txtnlsp.Value
        .Cells(lRow, 17).Value = Me.txtnlsp5.Value
        .Cells(lRow, 18).Value = Me.txtbkl.Value
        .Cells(lRow, 19).Value = Me.txtbkl5.Value
        .Cells(lRow, 20).Value = Me.txtbklsp.Value
        .Cells(lRow, 21).Value = Me.txtbklsp5.Value
        .Cells(lRow, 22).Value = Me.txtimp.Value
        .Cells(lRow, 23).Value = Me.txtimp5.Value
        .Cells(lRow, 24).Value = Me.txtlek.Value
        .Cells(lRow, 25).Value = Me.txtlek5.Value
        .Cells(lRow, 26).Value = Me.txtors.Value
        .Cells(lRow, 27).Value = Me.txtors5.Value
        .Cells(lRow, 28).Value = Me.txtudf.Value
        .Cells(lRow, 29).Value = Me.txtudf5.Value
        .Cells(lRow, 30).Value = Me.txtfom.Value
        .Cells(lRow, 31).Value = Me.txtfom5.Value
        .Cells(lRow, 32).Value = Me.txtcai.Value
        .Cells(lRow, 33).Value = Me.txtcai5.Value
        .Cells(lRow, 34).Value = Me.txtprc.Value
        .Cells(lRow, 35).Value = Me.txtprc5.Value
        .Cells(lRow, 36).Value = Me.txtrjc.Value
        .Cells(lRow, 37).Value = Me.txtrjc5.Value
    End With
[COLOR=#008000]    'Clear input controls.
[/COLOR]    Me.cboShift.Value = ""
    Me.cboPrd.Value = ""
    Me.txtTB.Value = ""
    Me.txtGP.Value = ""
    Me.txtTR.Value = ""
    Me.txtcap.Value = ""
    Me.txtcap5.Value = ""
    Me.txtbl.Value = ""
    Me.txtbl5.Value = ""
    Me.txtblsp.Value = ""
    Me.txtblsp5.Value = ""
    Me.txtnl.Value = ""
    Me.txtnl5.Value = ""
    Me.txtnlsp.Value = ""
    Me.txtnlsp5.Value = ""
    Me.txtbkl.Value = ""
    Me.txtbkl5.Value = ""
    Me.txtbklsp.Value = ""
    Me.txtbklsp5.Value = ""
    Me.txtimp.Value = ""
    Me.txtimp5.Value = ""
    Me.txtlek.Value = ""
    Me.txtlek5.Value = ""
    Me.txtors.Value = ""
    Me.txtors5.Value = ""
    Me.txtudf.Value = ""
    Me.txtudf5.Value = ""
    Me.txtfom.Value = ""
    Me.txtfom5.Value = ""
    Me.txtcai.Value = ""
    Me.txtcai5.Value = ""
    Me.txtprc.Value = ""
    Me.txtprc5.Value = ""
    Me.txtrjc.Value = ""
    Me.txtrjc5.Value = ""
End Sub

Sub cmdN_Click()
    'Close formW.
    Unload Me
End Sub

Is there anything wrong?
Any other suggestions to simply is also welcome :)

Thank you so much.
 
for the txtbx change the word Me. to Userform1
Code:
[COLOR=#ff0000]Me[/COLOR].TextBox
to
Code:
[COLOR=#ff0000]Userform1[/COLOR].Texbox
 
Last edited:
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top