P
Pat Dools
Hello,
I have a Command Button in which I do some checks on some required fields,
and if they are all filled in, I would like to call the 'SaveCloseForm'
module, which will attempt to save the record, and, if there is a Key
violation, will alert the user. Here is the code behind the Command Button:
Private Sub CommandCloseAndSave_Click()
If Len(Me.site.Value & "") = 0 Then
MsgBox "You must enter a value into Site Number."
Me.site.SetFocus
ElseIf Len(Me.id.Value & "") = 0 Then
MsgBox "You must enter a value into Patient Number."
Me.id.SetFocus
ElseIf Len(Me.ptin.Value & "") = 0 Then
MsgBox "You must enter a value into Patient Initials."
Me.ptin.SetFocus
ElseIf Len(Me.cyclenum.Value & "") = 0 Then
MsgBox "You must enter a value into Cycle."
Me.cyclenum.SetFocus
ElseIf Len(Me.examday.Value & "") = 0 Then
MsgBox "You must enter a value into Cycle."
Me.examday.SetFocus
ElseIf Len(Me.data1_init.Value & "") = 0 Then
MsgBox "You must enter a value into Data Entry 1 Initials."
Me.data1_init.SetFocus
Else
'Me.Refresh
'Call DoCmd.Close
Call SaveCloseForm
End If
End Sub
When I call to a Module, I get the error 'Expected variable or procedure,
not module', when I attempt to call 'SaveCloseForm' (see code):
Public Sub SaveCloseForm()
On Error GoTo Err_SaveCloseForm
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close
Exit_SaveCloseForm:
Exit Sub
Err_SaveCloseForm:
MsgBox Err.Description
Resume Exit_SaveCloseForm
End Sub
However, if I insert this as a Private Sub on the same Form and call it, it
works. However, this means I have to insert the same code on every form,
instead of calling it from one place. Why am I not allowed to call a Module
after the 'Else.. ' in my If Statement above?
Thanks.
I have a Command Button in which I do some checks on some required fields,
and if they are all filled in, I would like to call the 'SaveCloseForm'
module, which will attempt to save the record, and, if there is a Key
violation, will alert the user. Here is the code behind the Command Button:
Private Sub CommandCloseAndSave_Click()
If Len(Me.site.Value & "") = 0 Then
MsgBox "You must enter a value into Site Number."
Me.site.SetFocus
ElseIf Len(Me.id.Value & "") = 0 Then
MsgBox "You must enter a value into Patient Number."
Me.id.SetFocus
ElseIf Len(Me.ptin.Value & "") = 0 Then
MsgBox "You must enter a value into Patient Initials."
Me.ptin.SetFocus
ElseIf Len(Me.cyclenum.Value & "") = 0 Then
MsgBox "You must enter a value into Cycle."
Me.cyclenum.SetFocus
ElseIf Len(Me.examday.Value & "") = 0 Then
MsgBox "You must enter a value into Cycle."
Me.examday.SetFocus
ElseIf Len(Me.data1_init.Value & "") = 0 Then
MsgBox "You must enter a value into Data Entry 1 Initials."
Me.data1_init.SetFocus
Else
'Me.Refresh
'Call DoCmd.Close
Call SaveCloseForm
End If
End Sub
When I call to a Module, I get the error 'Expected variable or procedure,
not module', when I attempt to call 'SaveCloseForm' (see code):
Public Sub SaveCloseForm()
On Error GoTo Err_SaveCloseForm
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close
Exit_SaveCloseForm:
Exit Sub
Err_SaveCloseForm:
MsgBox Err.Description
Resume Exit_SaveCloseForm
End Sub
However, if I insert this as a Private Sub on the same Form and call it, it
works. However, this means I have to insert the same code on every form,
instead of calling it from one place. Why am I not allowed to call a Module
after the 'Else.. ' in my If Statement above?
Thanks.