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.

Actually there are several fields on this form similar to the one mentioned
that require the same outcome.

Anyone have a good suggestion that works?

Sincerely,
Rick J Riggins
 
J

John Vinson

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.

Actually there are several fields on this form similar to the one mentioned
that require the same outcome.

Anyone have a good suggestion that works?

Since a user can mouseclick into ANY control on the form, in any
order, I'd suggest just checking in the Form's BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Not IsNull(Me.DateRep) Then
If IsNull(Me.DateRepBy) Then
MsgBox "Please enter initials into Rep By:", vbOKOnly
Me.DateRepBy.SetFocus
Cancel = True
Exit Sub
End If
End If
<similar code for the other such cases>

You *can* use the afterupdate event of a control to disable all other
controls except for the desired one... but if I were one of your
users, I'd mutiny.

John W. Vinson[MVP]
 
G

Guest

John,

This 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?
 
J

John Vinson

This 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?

Presumably because the Print button doesn't save the record to disk.
Perhaps you could post the code in the Print button. Is it printing
the Form (not a good idea) or saving the record to disk and printing a
Report (much better)?

Note: you can save the record (triggering BeforeUpdate) using either

DoCmd.RunCommand acCmdSaveRecord

or

If Me.Dirty Then Me.Dirty = False

John W. Vinson[MVP]
 
G

Guest

John,

Here's the code I'm using to print the report, convaluted as it may be, it
works. I'm not sure what I need to include to stop the printing function
before all the required fields are entered. Any help would be greatly
appriciated.

Thanks,
Rick


Private Sub Print_Button_Click()
On Error GoTo Err_Print_Button_Click

Dim stDocName As String

stDocName = "Customer Info"
DoCmd.OpenReport stDocName, acNormal, , "[CustomerInfoID] = " &
[CustomerInfoID]

Exit_Print_Button_Click:
Exit Sub

Err_Print_Button_Click:
MsgBox Err.Description
Resume Exit_Print_Button_Click

End Sub
 
J

John Vinson

I'm not sure what I need to include to stop the printing function
before all the required fields are entered

ummmmm...

did you perchance try what both Allen and I suggested? It *will* work.

John W. Vinson[MVP]
 

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