I am learning VBA and following this youtube lesson:
I copied his code exact and when I assign the Show_form() macro to my shape on the work sheet the macro highlights yellow. Please see below:
Here's the 3 macros I wrote per the youtube:
Sub Reset()
Dim iRow As Long
iRow = [Counta(Database!A:A)] ' identify the last row
With frmform
.txtID.Value = " "
.txtName.Value = " ' "
.OptMale.Value = False
.OptFemale.Vlaue = False
.cmbDepartment.Clear
.cmbDepartment.AddItem "HR"
.cmbDepartment.AddItem "Operation"
.cmbDepartment.AddItem "Training"
.cmbDepartment.AddItem " Quality"
.txtCity.Value = " "
.txtCountry = " "
.lstDatabase.ColumnCount = 9
.lstDatabase.ColumnHeads = True
.lstDatabase.ColumnWidths = "30,60,75,40,60,45,55,70,70"
If iRow > 1 Then
.lstDatabase.RowSource = "Database!A2:I" & iRow
Else
.lstDatabase.RowSource = "Database!A2:I2"
End If
End With
End Sub
Sub Submit()
Dim sh As Worksheet
Dim iRow As Long
Set sh = ThisWorkbook.Sheets("Database")
iRow = [Counta(Database!A:A] + 1
With sh
.Cells(iRow, 1) = iRow - 1
.Cells(iRow, 2) = frmform.txtID.Value
.Cells(iRow, 3) = frmform.txtName.Value
.Cells(iRow, 4) = IIf(frmform.OptFemale.Value = True, "Female", "Male")
.Cells(iRow, 5) = frmform.cmbDepartment.Value
.Cells(iRow, 6) = frmform.txtCity.Value
.Cells(iRow, 7) = frmform.txtCountry.Value
.Cells(iRow, 8) = Application.UserName
.Cells(iRow, 9) = [Text(Now(),"DD-MM-YYYY HH:MM:SS")]
End With
End Sub
Sub Show_form()
frmform.Show
End Sub
Thank you,
Tony
I copied his code exact and when I assign the Show_form() macro to my shape on the work sheet the macro highlights yellow. Please see below:
Here's the 3 macros I wrote per the youtube:
Sub Reset()
Dim iRow As Long
iRow = [Counta(Database!A:A)] ' identify the last row
With frmform
.txtID.Value = " "
.txtName.Value = " ' "
.OptMale.Value = False
.OptFemale.Vlaue = False
.cmbDepartment.Clear
.cmbDepartment.AddItem "HR"
.cmbDepartment.AddItem "Operation"
.cmbDepartment.AddItem "Training"
.cmbDepartment.AddItem " Quality"
.txtCity.Value = " "
.txtCountry = " "
.lstDatabase.ColumnCount = 9
.lstDatabase.ColumnHeads = True
.lstDatabase.ColumnWidths = "30,60,75,40,60,45,55,70,70"
If iRow > 1 Then
.lstDatabase.RowSource = "Database!A2:I" & iRow
Else
.lstDatabase.RowSource = "Database!A2:I2"
End If
End With
End Sub
Sub Submit()
Dim sh As Worksheet
Dim iRow As Long
Set sh = ThisWorkbook.Sheets("Database")
iRow = [Counta(Database!A:A] + 1
With sh
.Cells(iRow, 1) = iRow - 1
.Cells(iRow, 2) = frmform.txtID.Value
.Cells(iRow, 3) = frmform.txtName.Value
.Cells(iRow, 4) = IIf(frmform.OptFemale.Value = True, "Female", "Male")
.Cells(iRow, 5) = frmform.cmbDepartment.Value
.Cells(iRow, 6) = frmform.txtCity.Value
.Cells(iRow, 7) = frmform.txtCountry.Value
.Cells(iRow, 8) = Application.UserName
.Cells(iRow, 9) = [Text(Now(),"DD-MM-YYYY HH:MM:SS")]
End With
End Sub
Sub Show_form()
frmform.Show
End Sub
Thank you,
Tony