I have written a couple of 'if' statements on a 'submit' button, but when i click the button most of the code seems to be ignored.
I wrote it with a single IF statement, and it worked perfectly. I added some more statements and everything else is being ignored.
I've closed the form and reopened it. I've closed access and reopened it. I've selected the specific button and checked its even procedure. Everything looks right, i dont understand why it's ignoring code.
I've tried 3 different methods to get it to prompt for specific information.
The only msgbox that pops up is the one referencing the Booking Date.
Method 1:
All fields set to 'Required: No"
Code:
'------------------------------------------------------------
' btnSubmit_Click
'
'------------------------------------------------------------
Private Sub btnSubmit_Click()
On Error GoTo btnSubmit_Click_Err
' _AXL:<?xml version="1.0" encoding="UTF-16" standalone="no"?>
' <UserInterfaceMacro For="btnExit" xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application"><Statements><Action Name="CloseWindow"/></Statements></UserInterfaceMacro>
On Error Resume Next
If IsNull(Me.cboAccountName) Or Me.cboAccountName = "" Then
MsgBox "Please select an account.", vbOKOnly, "Required Information"
Me.cboAccountName.SetFocus
Exit Sub
End If
If IsNull(Me.cboCustomerName) Or Me.cboCustomerName = "" Then
MsgBox "Please select a customer.", vbOKOnly, "Required Information"
Me.cboCustomerName.SetFocus
Exit Sub
End If
If IsNull(Me.cboVehicle) Or Me.cboVehicle = "" Then
MsgBox "Please select a Vehicle.", vbOKOnly, "Required Information"
Me.cboVehicle.SetFocus
Exit Sub
End If
If IsNull(Me.stBookingDate) Or Me.stBookingDate = "" Then
MsgBox "You need to insert a booking date!", vbOKOnly, "Required Information"
Me.stBookingDate.SetFocus
Exit Sub
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close acForm, "AddBooking", acSaveNoc
If (MacroError <> 0) Then
Beep
MsgBox MacroError.Description, vbOKOnly, ""
End If
btnSubmit_Click_Exit:
Exit Sub
btnSubmit_Click_Err:
MsgBox Error$
Resume btnSubmit_Click_Exit
End Sub
Method 2:
All fields set to 'Required: No'
Code:
Private Sub btnSubmit_Click()On Error GoTo btnSubmit_Click_Err
' _AXL:<?xml version="1.0" encoding="UTF-16" standalone="no"?>
' <UserInterfaceMacro For="btnExit" xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application"><Statements><Action Name="CloseWindow"/></Statements></UserInterfaceMacro>
On Error Resume Next
If IsNull(Me.cboAccountName) Or Me.cboAccountName = "" Then
MsgBox "Please select an account.", vbOKOnly, "Required Information"
Me.cboAccountName.SetFocus
Exit Sub
Else
If IsNull(Me.cboCustomerName) Or Me.cboCustomerName = "" Then
MsgBox "Please select a customer.", vbOKOnly, "Required Information"
Me.cboCustomerName.SetFocus
Exit Sub
Else
If IsNull(Me.cboVehicle) Or Me.cboVehicle = "" Then
MsgBox "Please select a Vehicle.", vbOKOnly, "Required Information"
Me.cboVehicle.SetFocus
Exit Sub
Else
If IsNull(Me.cboVehicle) Or Me.cboVehicle = "" Then
MsgBox "Please select a Vehicle.", vbOKOnly, "Required Information"
Me.cboVehicle.SetFocus
Exit Sub
Else
If IsNull(Me.stBookingDate) Or Me.stBookingDate = "" Then
MsgBox "You need to insert a booking date!", vbOKOnly, "Required Information"
Me.stBookingDate.SetFocus
Exit Sub
End If
End If
End If
End If
End If
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close acForm, "AddBooking", acSaveNoc
If (MacroError <> 0) Then
Beep
MsgBox MacroError.Description, vbOKOnly, ""
End If
btnSubmit_Click_Exit:
Exit Sub
btnSubmit_Click_Err:
MsgBox Error$
Resume btnSubmit_Click_Exit
End Sub
Method 3:
Using the above code and setting the desired fields to be Required via the Table settings.