Make Entry Manditory Under Certain Conditions

Neilbees

Registered User.
Local time
Today, 14:03
Joined
Oct 30, 2006
Messages
51
Hi. Apologies for starting a new thread but I can't find anything in the forums that cover this. I think I just can't figure out what to search for!

I have a text box on a form called SAPRequisitionNo. Basically, I want to make entry into this text box compulsory if there is an entry in either 1stProofActual or PaperToPressActual (both of these are date entires by the user). Until users enter a date in either one of these boxes they won't have anything for the SAPRequisitionNo so it can remain blank until they do.

I think that makes sense. Any suggestions gratefully received!
 
Simple Software Solutions

Hi

Form what I gather the user must enter something into the first field if either of the date fields has a date in them.

What you could try is on the GotFocus of either of the date fields is to state

If datefield1 <> "" Or datefield2 <> "" And TextField1 = "" Then
TextField1.SetFocus
End If

What will happen is that when the user clicks on any of the two date fields it examines the other date field and tests for an value. If neither of them have a value AND the text field does NOT have a value then set focus on the Text field. This means the user has to enter something in the text field and at least one value in either of the date fields for them to progress.

Hope this works for you.
 
Validation is generally done in the BeforeUpdate event of either controls or the form itself. Since your validation depends on the state of more than one control, the form BeforeUpdate is the event to use.

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
 If Len(Me.FirstProofActual & "") <> 0 Or Len(Me.PaperToPressActual & "") <> 0 Then
  If IsNull(Me.SAPRequisitionNo) Then
   Cancel = True
   MsgBox "You must enter data in the SAPRequisitionNo field!"
   SAPRequisitionNo.SetFocus
  End If
 End If
End Sub
Notice that I've changed 1stProofActual to FirstProofActual. Access doesn't like object names that start with digits, and if you name a textbox 1stProofActual, in the code window it'll actually change it to Ctl1stProofActual, which is confusing.

Linq
 
Access doesn't like object names that start with digits, and if you name a textbox 1stProofActual, in the code window it'll actually change it to Ctl1stProofActual, which is confusing.

Linq

Pardon me 'hijacking' this post, but missinglinq, does this mean if I have set my table structure (and queries & forms) based on 1, 2, 3tblxxx etc, I am heading for a disaster???
 

Users who are viewing this thread

Back
Top Bottom