New to VBA

shevo

Registered User.
Local time
Tomorrow, 03:22
Joined
Jun 3, 2007
Messages
16
Hi,
I am using VBA for the first time. I am trying to check for expiry date as I move through each of the records. However I am not sure how to go about doing that. I have only put the codes in the Form load event and I can't seems to find any Form change event or record change event. Appreciate any advises.:D

Private Sub Form_Load()
DoCmd.GoToControl "txtExpiryDate"
If txtExpiryDate.Text < Now() Then
DoCmd.GoToControl "txtTest"
txtTest.Text = "Expired!"
End If
End Sub
 
The Current event fires when you change records.
 
I can't seems to see the change as I scroll through the records. Is there any problem with my code as I need to display the current status for each record in the form as "Expired" or "Not Expired".
 
Change it to:

Code:
If Me.txtExpiryDate < Date Then
   Me.txtTest = "Expired!"
End If

You don't need to use .TEXT as the control needs the focus when you use that. You just reference the .Value instead and since .Value is the default you don't need to explicitly use .value, but can just use it the way I wrote it.

Also, if your field is not storing Date AND Time you can use DATE instead of NOW.
 
I can't seems to see the change as I scroll through the records.
Did you put your code on the Current event instead of of the event you have listed in the first thread?

Paul has already said this...
 
Change it to:

Code:
If Me.txtExpiryDate < Date Then
   Me.txtTest = "Expired!"
End If

You don't need to use .TEXT as the control needs the focus when you use that. You just reference the .Value instead and since .Value is the default you don't need to explicitly use .value, but can just use it the way I wrote it.

Also, if your field is not storing Date AND Time you can use DATE instead of NOW.

Thanks for the prompt reply, but output textbox which display "Expired" doesn't change as I scroll through each records.
 
You have to add an Else clause to deal with the other option.
 

Users who are viewing this thread

Back
Top Bottom