Autofill date based on another field (1 Viewer)

Marjoram

New member
Local time
Today, 07:45
Joined
Feb 13, 2019
Messages
3
Hi


I have two fields, Ready_Despatch (Y/N) and Ready_Date (Date field).


I want Ready_Date to automatically input today's date when Ready_Despatch has a Y.


I've tried doing an After update on the Ready_Despatch field as per below but nothing populates in Ready_date when Ready_despatch changes to Y.



Private Sub Ready_Despatch_AfterUpdate()

If Me.Ready_Despatch = True Then
Me.Ready_date = Date
Else
Me.Ready_date = Null
End If
End Sub



Help will be much appreciated :)
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:45
Joined
Sep 21, 2011
Messages
14,232
For 'silly' errors like this, I always walk through the code with F8 in the debug window.
By silly, I mean it looks like it should work, but for some reason it does not.

To me, your code looks OK, as long as the names are correct.?
Place a breakpoint on the If statement and inspect the value by hovering with the mouse or ? Me.Ready_Despatch in the Immediate window.

HTH
 

isladogs

MVP / VIP
Local time
Today, 07:45
Joined
Jan 14, 2017
Messages
18,209
Agree with previous comments. Find out whether it follows the True branch when you think it should.
If not, try explicitly saving before the If line using If Me.Dirty Then Me.Dirty=False
 

Marjoram

New member
Local time
Today, 07:45
Joined
Feb 13, 2019
Messages
3
Thanks for the replies.



I can get it to work with On Click, so maybe it has to do with the properties of the Y/N field. It's as if it is not picking up that it is True or "Y".



The Y/N field is a combo box with a Row Source N;Y and value list. Not sure if this would make any difference in the way the code picks up the value to be true.



Sorry my knowledge of VBA is limited.
 

isladogs

MVP / VIP
Local time
Today, 07:45
Joined
Jan 14, 2017
Messages
18,209
Sorry - as its a Yes/No field, the OnClick event is better.
Just make sure it works the 'correct way round'
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:45
Joined
Sep 21, 2011
Messages
14,232
You are not setting Ready_Despatch via code are you.?

I don't believe the AfterUpdate event fires if that is the case, however the breakpoint will identify that.
 

Users who are viewing this thread

Top Bottom