I'm checking for required fields, and using the code below, which I normally
have no difficulties with; however, as a twist I decided to return the focus
back to the specific field(s) in question for input.
Under the "Case vbYes" I indicated the two required fields to return the
focus, based on which one is empty, however, I cannot seem to return the
focus. If I only have one field indicated in the code, example;
If Me.txtUDateStart = " " Then
Me.txtUDateStart.SetFocus
Then all is fine, but with both, it will not return the focus to either
field.
Any help appreciated!
Cheers,
Dave
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMissing As String
Dim CRLF As String
DoCmd.SetWarnings False
' line feed
CRLF = Chr(10) & Chr(13)
' 1st field value is null?
strMissing = IIf(IsNull(Me.txtUDateStart), " - Start Date" + CRLF, "")
' 2nd field value is null?
strMissing = strMissing & IIf(IsNull(Me.txtUName), " - Unit name" + CRLF,
"")
' Any required field was null?
If strMissing <> "" Then
' No update
Cancel = True
' ask user is (s)he wants to enter data or cancel
Select Case MsgBox("Required information is missing: " & vbCrLf & ""
_
& CRLF & strMissing & vbCrLf & "Do you want to enter the missing "
_
& "data?" & vbCrLf & "" & vbCrLf & "NOTE: Selecting ""No"" will
clear " _
& "any incomplete data entries", vbYesNo Or vbQuestion Or _
vbDefaultButton1, "Data missing")
Case vbYes
If Me.txtUDateStart = " " Then
Me.txtUDateStart.SetFocus
ElseIf Me.txtUName = " " Then
Me.txtUName.SetFocus
End If
Case vbNo
Me.Undo
End Select
End If
DoCmd.SetWarnings True
End Sub