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

Problems with checking two date fields

Status
Not open for further replies.

vikunja

Technical User
Jun 6, 2002
18
NO
Hi

In one of my forms I have a start and end date. The end date has a criteria which is that it shouldn't be an earlier date than the first. I use this piece of code with the "on change" event:

Private Sub ETD_Dato_BeforeUpdate(Cancel As Integer)

If Me![ETD Dato] < Me![ETA Dato] Then
MsgBox &quot;The ETD date is earlier than ETA date, please change ETD date&quot;

Cancel = True
Exit Sub
End If

End Sub

This piece of code worked when I manually wrote in the two dates. But after I have gone over to using calender control for the two dates, the above mentioned code does not seem to do anything.

Appreciate any help

Thanks in advance

Alexi
 
Although you haven't said it explisitly, I think you problem is that you are setting the value of the text box from the value returned bu the Calendar cotrol using code.

Setting the value of a control by using a macro or Visual Basic doesn't trigger the ON_Change event for the control. You must type the data directly into the control, or set the control's Text property.



'ope-that-'elps.

G LS

 
Hi GLS

Thanks for answering.

You're probably right about the values being set into the field. As I am new at programming in ACCESS and using forms I wandered if you could tell me how I set the controls TEXT property as you mentioned above.

again, thank you for your help

Alexi
 
Well, what I mean is that somewhere ( probobly in the Calendar control's AfterUpdate event you have some code that does something like:-

Me![ETD Dato] = CalControl


What the original note means is relpace the above with

[ETD Dato].SetFocus
[ETD Dato].Text = CalControl

( The Me! is not needed because you have a contol of that name on the form. But you need to do the .SetFocus because .Text requires the control to have the focus at the time. )



As a side line:-
Avoid 'like the plague' names with spaces in.
One minor benefit is that you'll never need to type '[' or ']' again.
There are also other greater benefits that will become apparent as you get more into coding.



'ope-that-'elps.

G LS

 
HI

It didn't work, however after you told me about that the calender values were the reason why i couldn't test the two dates I found out that I could compare the two calender date values. The test is now working.

Thanks for all your help!

Alexi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top