Making a list of Null Required Fields

  • Thread starter Thread starter scott04
  • Start date Start date
S

scott04

Hello,
I was just writing some code to make sure agents are entering required
fields. Please see below as an example. After some thinking i was wondering
if it would be easier to have the message box states all of the fields that
are null rather than going one by one. How would that be written? So my
message box would state something like
Please enter the following
*case number
*plaintiff's name
ect....

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strPE As String
strPE = "Please enter the "
f IsNull(Me.Case_No) Then
MsgBox strPE & "case number", vbCritical
Cancel = True
Case_No.SetFocus
ElseIf IsNull(Me.Plaintiff_s_Name) Then
MsgBox strPE & "plaintiff's name", vbCritical
Cancel = True
Plaintiff_s_Name.SetFocus
Ect....

Thank you.
 
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String

If IsNull(me.Case_No) Then
Cancel = True
strMsg =strMsg & "Case number required." & vbCrLf
End If

If IsNull(Me.Plaintiff_s_Name) Then
Cancel= True
strMsg = strMsg & "Plantiff name required." & vbCrLf
End If

' etc

If Cancel then
strMsg = strMsg & vbCrLf & "Correct the entry, or press <Esc> to
undo."
MsgBox strMsg, vbExclamation, "Invalid entry"
End If
End Sub
 
On Fri, 19 Sep 2008 06:02:01 -0700, scott04

What I do is to give required fields a different background color.
Then simply let Access take care of validating if the current record
can be saved.

If you really want to, you can inspect the Required property of the
Field object of the underlying RecordsetClone to see which ones are
required.

-Tom.
Microsoft Access MVP
 
Thanks Allen

Allen Browne said:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String

If IsNull(me.Case_No) Then
Cancel = True
strMsg =strMsg & "Case number required." & vbCrLf
End If

If IsNull(Me.Plaintiff_s_Name) Then
Cancel= True
strMsg = strMsg & "Plantiff name required." & vbCrLf
End If

' etc

If Cancel then
strMsg = strMsg & vbCrLf & "Correct the entry, or press <Esc> to
undo."
MsgBox strMsg, vbExclamation, "Invalid entry"
End If
End Sub
 
Back
Top