Required sometimes

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
 
G

Graham R Seach

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top