Code:
Public Function validateform(myform As Form) As Boolean
'returns true if all required fields have data, or false if not.
'It will also create a popup message explaining which fields need data
Dim boolresponse As Boolean
Dim strError As Variant
Dim ctl As Control
boolresponse = True
'starting off the boolean response as true
strError = Null
'the error is defined as null
With myform
For Each ctl In .Controls
With ctl
If .Tag = "required" Then
If .Value & "" = "" Then
boolresponse = False
strError = (strError + ", ") & .Name
End If
End If
End With
Next ctl
End With
If strError & "" <> "" Then strError = MsgBox("The following information must be entered first: " & strError, vbOKOnly + vbInformation)
validateform = boolresponse
End Function
Private Sub NewSave_Button_Click()
Dim enterfieldsmsg As Variant
On Error GoTo Err_NewSave_Button_Click
If Me.ContractNumber & "" <> "" Or Me.ContractValue & "" <> "" Then
If validateform(Me) Then
DoCmd.GoToRecord , , acNewRec
DoCmd.RunCommand acCmdSave
Me.AmountPaid.Visible = False
Me.Notes.Visible = False
Else
enterfieldsmsg = MsgBox("Enter all fields", vbOKOnly + vbCritical, "Missing Information")
End If
End If
Exit_NewSave_Button_Click:
Exit Sub
Err_NewSave_Button_Click:
MsgBox Err.Description
Resume Exit_NewSave_Button_Click
The code is above, do you have any suggestions to make the msg work? cause right now this code is blocking my ability to send error messages for duplicate entries etc.
*sigh*