Hi all, I'm still a Novice at VBA, but here's what I'm trying to do...
I have several controls that do certain things, and before they do them, they save the form. But I have some data validation I want to do before I save the form...
Rather than copy that data validation to each sub, I thought I'd throw it in a function to make it cleaner and easier to update later...
I'm not sure if I wrote the function wrong, or I'm just not calling it correctly, but it doesn't seem to work...
here's the function:
Code:
Public Function IncompleteData() As Integer
If (Me.PartNum & "") = "" Then
MsgBox "Please Enter a Part Number", vbInformation, "Incomplete Data"
Me!PartNum.SetFocus
IncompleteData = 1
Exit Function
ElseIf (Me.Manufacturer & "") = "" Then
MsgBox "Please Enter a Manufacturer", vbInformation, "Incomplete Data"
Me.Manufacturer.SetFocus
IncompleteData = 2
Exit Function
End If
IncompleteData = 0
End Function
And here's an example of my calling the function:
Code:
Private Sub cmdSave_Click()
If IncompleteData() <> 0 Then Exit Sub
If Me.Dirty Then Me.Dirty = False
DoCmd.Close
End Sub
When I click cmdSave with PartNum blank, I get no messagebox and Partnum is set to focus.
When I click cmdSave with Partnum filled in, but Manufacturer blank, I get no message box, and the record is SAVED with a blank manufacturer field...
What am I doing wrong??