Conditional Fields

G

Guest

OK. Next question. I have two textbox fields on a form "DateRep" and
"DateRepBy".

I need to link these fields so that when information is entered into the
"DateRep" field, the "DateRepBy" field requires initials to be entered before
continuing.
 
A

Allen Browne

Because you are comparing 2 fields, use the BeforeUpdate event procedure of
the form (not controls) to perform this validation.

This kind of thing:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
If IsNull(Me.DateRepBy) And Not IsNull(Me.DateRep) Then
Cancel = true
strMsg = "Initials required when you enter DateRep."
MsgBox strMsg, vbExclamation, "Invalid data"
Me.DateRepBy.SetFocus
End If
End Sub
 
G

Guest

Allen. Thanks for the response, and your suggestion works. Sort of.
Unfortunately I have several fields on this form similar to the one
previously mentioned so I need something that works within a control.

Could you you suggest something that might work?

Sincerely
Rick J Riggins
 
A

Allen Browne

What do you mean, "works within a control?"

Do you mean that if hte user goes to the DateRep field *before* entering
their initials, it should refuse to accept a date, force them to enter their
initials, and then let them come back later and enter the date?

You can cancel the BeforeUpdate event of the control if you wish. That
doesn't make sense to me, though: Access (and Windows) is event-driven, so
the user can click in the controls in any order, and might not even visit a
control you are interested in.
 
G

Guest

Allen,

Your Idea works great except when I hit the print button. No error message
and the print command is carried out without a response to the
Form_BeforeUpdate paramiter. Any idea why?
 

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