Hi ihave been following a youtube video to create a form to input data. once this was completed I was hoping I could share this only issue I have is when I click my save button I get message:
Run-time '91':
Object variable or WIth variable not set
when I click debug it highlights this section:
Code
'find first empty row in database
iRow = ws.Cells.Find(What:="*", _
SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, _
LookIn:=xlValues).Row + 1
Can you advise me where I am going wrong I have also included below the full code
Code
Private Sub cdmbutton_AddDetails_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", _
SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, _
LookIn:=xlValues).Row + 1
'check for a Name number
If Trim(Me.textbox_IntroducedBy.Value) = "" Then
Me.textbox_IntroducedBy.SetFocus
MsgBox "Please complete the form"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.textbox_IntroducedBy.Value
ws.Cells(iRow, 2).Value = Me.textbox_ReferredTo.Value
ws.Cells(iRow, 3).Value = Me.textbox_ClientName.Value
ws.Cells(iRow, 4).Value = Me.textbox_PolicyType.Value
ws.Cells(iRow, 5).Value = Me.textbox_CSR.Value
ws.Cells(iRow, 6).Value = Me.textbox_DatePolicyOnCover.Value
ws.Cells(iRow, 7).Value = Me.textbox_OGIOReferance.Value
ws.Cells(iRow, 8).Value = Me.textbox_Premium.Value
ws.Cells(iRow, 9).Value = Me.textbox_Commission.Value
ws.Cells(iRow, 10).Value = Me.textbox_Fees.Value
ws.Cells(iRow, 11).Value = Me.textbox_Total.Value
ws.Cells(iRow, 12).Value = Me.textbox_CommissionAt20.Value
ws.Cells(iRow, 13).Value = Me.textbox_CommissionAt10.Value
ws.Cells(iRow, 14).Value = Me.textbox_Audited.Value
End Sub
Private Sub cdmbutton_CloseForm_Click()
Unload Me
End Sub
Display More
Thanks