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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Requiring unbound field entry 3

Status
Not open for further replies.

Blondie96

Programmer
Aug 12, 2004
119
US
I have a form, it requests a start date.

I want to make sure that a valid date is entered into this field, before goint to the next field which is startTime.
If no valid date is entered I want the cursor to return to the StartDate field.

How would I go about doing this (& in which event procedures)

Thanks,

Tamra
 
Take a look at the IsDate function and the SetFocus method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Set the format property of the textbox to dd/mm/yyyy. Set an input mask of 00/00/0000;0;_

You could code it as well, but I believe this is over-complicating the solution unless you want to display a custom error message or change the point at which the message is displayed.

Ed Metcalfe.

Please do not feed the trolls.....
 
I put in the format property & input mask, that formatted it but didn't stop it from leaving the field if no data was input.

I tried the IsDate() that gave me an error, but still went to the next field, even when i combined it with the setfocus.currentfield (with proper field name)

I have only been able to use the setfocus from within the onfocus of the next field, resetting it to the previous field.

Is there a way to check before leaving the field & stop the focus from moving to the next field.

Reason:

I can enter 1 to 5 requests each with a
start & end Date & time. I need to check that last time before it tries to go to the next field because the user may not go to the next field.
 
Tamra

Try something like this along with the InputMask

Private Sub txtStartDate1_AfterUpdate()
If Not IsDate(txtStartDate1) Then
Me.txtEndDate2.SetFocus
MsgBox "A Date Is Required"
Me.txtStartDate1.SetFocus
End If
End Sub

PaulF
 
I tried:

in onlostfocus_cboendhour1:
If IsNull(cboEndHour1) Then
MsgBox "End Hour Required."
Forms!MakeSchedule!EndDate1.SetFocus
Forms!MakeSchedule!cboEndHour1.SetFocus
Exit Sub
End If

I got the msgbox twice, then it returned to the hour field like i wanted... just not 2 messages.

I tried
afterupdate_cboEndHour
If IsNull(cboEndHour1) Then
MsgBox "End Hour Required."
Forms!MakeSchedule!EndDate1.SetFocus
Forms!MakeSchedule!cboEndHour1.SetFocus
Exit Sub
End If

It gave the error message, but continued to the next field anyway
 
you might look at using the Form's BeforeUpdate Event to check for entries in each textbox, combobox and use the AfterUpdate and InputMask to check formatting..
In the Form's BeforeUpdate event, check each of the controls you want to ensure contains data, and if they don't, inform the user, and then cancel the event with Cancel= True or DoCmd.CancelEvent


PaulF
 
How about setting the 'required' property of the field in the table to yes.

Ian Mayor(UK)



Program Error
Programmers do it one finger at a time!
 
Well, it's an unbound form, so there's no table field to set.
 
Well, the simplest things are the hardest to find. The code to check the endDate worked the first time. Then when I checked for endtime<starttime (valid if endDate > startDate) if it was invalid, I moved "" to EndHour & EndDate, then set focus to endDate. When it got to start time however it no longer worked.

The stupid (or easy) part... I was checking
"IsNull(EndTime)". It turns out, much to my frustration, the two are not the same. I set the fields to null, set cancel=True, put the code in the OnExit sub & everything works fine.

Thanks everyone for the help.

Tamra
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top