Required sometimes

  • Thread starter Thread starter Dan @BCBS
  • Start date Start date
D

Dan @BCBS

,I need to make a text box Required - But not all the time!!
If another field "A" is not blank make field "B" required...

Something like this, but "Required" obviously, does not work!!

If Me.CA_NAME <> " " Then
Me.CA_DATEFRWD = Required

Thanks
 
Dan,

You'll have to write some code for this. Let's say you want to check for the
requirement before a record is created or updated. In that case, put the
following procedure into your form.

Private Function DoINeedB() As Boolean
If Len("" & Me!TextboxA) > 0 Then
If Len("" & Me!TextboxB) = 0 Then
DoINeedB = True
MsgBox "You must enter a value for TextboxB"
End If
End If
End Sub

Then call it from the form's BeforeUpdate and BeforeInsert events, like so:

Private Sub Form_BeforeInsert(Cancel As Integer)
Cancel = DoINeedB
End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
Cancel = DoINeedB
End Sub

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Back
Top