T. McConnell
Registered User.
- Local time
- Today, 12:50
- Joined
- Jun 21, 2019
- Messages
- 63
Hey everyone, I am need of help once again. Working on a simple expense tracker database. On the form I have two different comboboxes that based on certain selections with make some textfields visible. On the first combobox (ExpType) there are 3 different options within the list that if selected shows other textboxes on the form. (the options are Customer, Nextgear, and TBA)
The other combobox (MethodOfPayment) has one option (Check) that if selected will show a textbox (CheckNumber)
What I am wanting to do is basically if either of the first 3 options are selected to verify the fields aren't null before submitting the record. The same goes for the CheckNumber box, if null then give message to go back and enter.
The code I have used is below , however I have tried different ways of doing this with no luck. Basically what happens if there are any errors it does catch them and provides the error message, but if all fields are not null and are filled out properly, the Save button doesn't do anything. Any suggestions???
I am sure there is a better way to do this, so I am open to suggestions.
Thanks again for any help. I can provide a sample of the DB if needed as still in testing.
The other combobox (MethodOfPayment) has one option (Check) that if selected will show a textbox (CheckNumber)
What I am wanting to do is basically if either of the first 3 options are selected to verify the fields aren't null before submitting the record. The same goes for the CheckNumber box, if null then give message to go back and enter.
The code I have used is below , however I have tried different ways of doing this with no luck. Basically what happens if there are any errors it does catch them and provides the error message, but if all fields are not null and are filled out properly, the Save button doesn't do anything. Any suggestions???
Code:
Private Sub btnSave_Click()
If Me.MethodOfPayment = "Check" Then
If IsNull(Me.CheckNumber) Then
If MsgBox("Please Enter a Valid Check Number", vbRetryCancel, "Incorrect Check Number") = vbRetry Then
Me.CheckNumber.SetFocus
Else
If MsgBox("Are you sure you want to submit this Expense?", vbOKCancel, "Submit Expense?") = vbOK Then
DoCmd.RunCommand (acCmdSaveRecord)
DoCmd.RunCommand (acCmdRecordsGoToNew)
Me.ExpenseSummary.Requery
Exit Sub
End If
End If
End If
End If
If Me.ExpType = "Customer" Then
If IsNull(Me.Customer) Or IsNull(Me.CarYear) Or IsNull(Me.CarMake) Or IsNull(Me.CarModel) Or IsNull(Me.CarColor) Or IsNull(Me.PurchaseLocation) Then
If MsgBox("Please Enter a Customer and Vehicle Information", vbRetryCancel, "Select Customer") = vbRetry Then
Me.Customer.SetFocus
Else
If MsgBox("Are you sure you want to submit this Expense?", vbOKCancel, "Submit Expense?") = vbOK Then
DoCmd.RunCommand (acCmdSaveRecord)
DoCmd.RunCommand (acCmdRecordsGoToNew)
Me.ExpenseSummary.Requery
Exit Sub
End If
End If
End If
End If
If Me.ExpType = "NextGear" Then
If IsNull(Me.CarYear) Or IsNull(Me.CarMake) Or IsNull(Me.CarModel) Or IsNull(Me.CarVIN) Or IsNull(Me.PurchaseLocation) Then
If MsgBox("Please Enter Vehicle Information", vbRetryCancel, "Enter All Vehicle Information") = vbRetry Then
Me.CarYear.SetFocus
Else
If MsgBox("Are you sure you want to submit this Expense?", vbOKCancel, "Submit Expense?") = vbOK Then
DoCmd.RunCommand (acCmdSaveRecord)
DoCmd.RunCommand (acCmdRecordsGoToNew)
Me.ExpenseSummary.Requery
Exit Sub
End If
End If
End If
End If
If Me.ExpType = "TBA" Then
If IsNull(Me.CarYear) Or IsNull(Me.CarMake) Or IsNull(Me.CarModel) Or IsNull(Me.CarVIN) Or IsNull(Me.PurchaseLocation) Then
If MsgBox("Please Enter Vehicle Information", vbRetryCancel, "Enter All Vehicle Information") = vbRetry Then
Me.CarYear.SetFocus
Else
If MsgBox("Are you sure you want to submit this Expense?", vbOKCancel, "Submit Expense?") = vbOK Then
DoCmd.RunCommand (acCmdSaveRecord)
DoCmd.RunCommand (acCmdRecordsGoToNew)
Me.ExpenseSummary.Requery
Exit Sub
End If
End If
End If
End If
If IsNull(Me.ExpDescription) Or IsNull(Me.ExpType) Or IsNull(Me.Amount) Or IsNull(Me.MethodOfPayment) Then
If MsgBox("Please Enter Expense Details", vbRetryCancel, "Enter All Expense Information") = vbRetry Then
Me.ExpDescription.SetFocus
Else
If MsgBox("Are you sure you want to submit this Expense?", vbOKCancel, "Submit Expense?") = vbOK Then
DoCmd.RunCommand (acCmdSaveRecord)
DoCmd.RunCommand (acCmdRecordsGoToNew)
Me.ExpenseSummary.Requery
Exit Sub
End If
End If
End If
End Sub
I am sure there is a better way to do this, so I am open to suggestions.
Thanks again for any help. I can provide a sample of the DB if needed as still in testing.