Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation Rule

Status
Not open for further replies.

jake7363

Technical User
May 31, 2006
56
Hello,
I have two fields (call them field 1 and field 2), which are both formatted for "General Date". Since they are used in a calculation of Date and time, I need both segments to be entered.
Is there a way I can create a validation rule that doesn't allow data unless it is mm/dd hh:mm am/pm? The users are entering one part or another, but not both, and I would like to deter that.

If this is not possible, any suggestions are welcome.

Thanks in advance,
Jake
 
Why two fields for a single date/time? With two fields, you will have to use either an update event or a control formatted for date/time, which can be split for the two fields. It is more awkward.
 
Apologies for not being clearer. One field represents a start date/time, while the other represents the end date/time. I am calculating the time consumed, including when it runs for more than 24 hours.

Hope this clarifies...
 
Here are some notes:
Code:
'Format: dd/mm/yyyy hh:nn:ss am/pm
'Input mask: 00\/00\/0000\ 00\:00:00\ aa;0
Private Sub EndDate_Exit(Cancel As Integer)
If Not IsNull(Me.StartDate) And IsNull(Me.EndDate) Then
    If MsgBox("No data. Cancel?", vbYesNo) = vbYes Then
        Me.Undo
    Else
        Cancel = True
    End If
End If

End Sub

Private Sub StartDate_AfterUpdate()
If IsNull(Me.EndDate) Then Me.EndDate.SetFocus
End Sub

Private Sub Form_Error(DataErr As Integer, Response As Integer)
Const INPUTMASK_VIOLATION = 2279
If DataErr = INPUTMASK_VIOLATION Then
    MsgBox "There was an input mask violation!"
    Response = acDataErrContinue
End If
End Sub
 
This looks like it will work. I will give it a try.

Much Thanks!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top