module?
Hi,
I'm new to using modules so I don't know how to fix what I'm doing wrong. Basically, I want a Yes/No Message box to run on exit from a required field. I have five of these fields, so I'd rather not have to copy/paste the same stuff five times but rather call the same code from a module. I'd like to assign names in the OnExit sub then just call the module. Regular hardcoding works just fine, it's just when I'm trying to assign aliases that thing stop working, specifically I get a "Argument not optional" error at the line in red below. I know this is wrong, but how should it be coded? And can I even do this this way?
Also, any good online reference for beginner module-users would be much appreciated. Thanks!
On Exit sub
Private Sub StudyID_Exit(Cancel As Integer)
Dim stDocName As String
stDocName = "StudyID"
Dim stExit As Integer
stExit = StudyID_Exit
Call Clear(Me)
End Sub
module
Public Sub Clear(objform As Form)
Dim stDocName As String
Dim stExit As Integer
If IsNull(objform.stDocName) Or objform.stDocName = "" Then
stExit = MsgBox("A required field is missing. You need to fill in the field or you will lose the record. Do you want to keep this record?" _
, vbYesNo, "Stop")
If stExit = vbYes Then
DoCmd.CancelEvent
ElseIf stExit = vbNo Then
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
If SelTop = 1 Then
DoCmd.GoToRecord , , acNext
StudyID.SetFocus
Else
DoCmd.GoToRecord , , acPrevious
StudyID.SetFocus
End If
End If
End If
End Sub
|