myoungii
Apr 6, 2011, 12:44 AM
I am attempting to create an if statement with multiple variables. I have a form that user will fill out but I do not want them to be able to save any information if any number of the three controls are left blank.
Private Sub cmdSave_Click()
On Error GoTo HandleError
If me.txtdate.value <> "" And Me.cboShift.Value <> "" And me.cboSection.value <> = "" Then
intResponse = MsgBox("Are you sure you want to save the shift summary information " & Me.cboShift And "shift - " & me.cboSection & " for " & Me.txtDate & ".", vbYesNo)
Exit Sub
Else
'Call CheckMaintanceSchedule
If lngShiftSummary = 0 then
Call InsertShiftSummary
Else
Call UpdateShiftSummary
Call Form_Load
End If
End If
Else
MsgBox "A date, shift, and section must be provided in order to save the shift summary information on the form. Please provide this information.", vbOKOnly
Me.txtDate.SetFocus
End If
HandleError:
If Err.Number <> 0 Then
GeneralErrorHandler Err.Number, Err.Description, SHIFT_SUMMARY_DETAILS_FORM, "cmdSave_Click"
Exit Sub
End If
End Sub
The code appears to runs through the IF statement fine but then skips the "intResponse line and immediately jumps to the Handle error code. Does anyone have any suggestions?
Private Sub cmdSave_Click()
On Error GoTo HandleError
If me.txtdate.value <> "" And Me.cboShift.Value <> "" And me.cboSection.value <> = "" Then
intResponse = MsgBox("Are you sure you want to save the shift summary information " & Me.cboShift And "shift - " & me.cboSection & " for " & Me.txtDate & ".", vbYesNo)
Exit Sub
Else
'Call CheckMaintanceSchedule
If lngShiftSummary = 0 then
Call InsertShiftSummary
Else
Call UpdateShiftSummary
Call Form_Load
End If
End If
Else
MsgBox "A date, shift, and section must be provided in order to save the shift summary information on the form. Please provide this information.", vbOKOnly
Me.txtDate.SetFocus
End If
HandleError:
If Err.Number <> 0 Then
GeneralErrorHandler Err.Number, Err.Description, SHIFT_SUMMARY_DETAILS_FORM, "cmdSave_Click"
Exit Sub
End If
End Sub
The code appears to runs through the IF statement fine but then skips the "intResponse line and immediately jumps to the Handle error code. Does anyone have any suggestions?