Can a selection in a combo box trigger today's date to appear in another field? (1 Viewer)

templeowls

Registered User.
Local time
Today, 14:36
Joined
Jun 11, 2019
Messages
155
I have a form with a combo box (the selections are Yes and No, with the default being No). If yes is selected, is it possible for today's date to be populated in a completely seperate date field?

I can provide an example DB if helpful
 

Minty

AWF VIP
Local time
Today, 22:36
Joined
Jul 26, 2013
Messages
9,238
Yes. In the after update event of the combo

Me.YourDateFieldControl = Date()
 

templeowls

Registered User.
Local time
Today, 14:36
Joined
Jun 11, 2019
Messages
155
Forgive me. The choices are N/A, No, and Yes (N/A is default). Is there a way to code it so that "yes" is the only selection that triggers the date?
 

isladogs

CID VIP
Local time
Today, 22:36
Joined
Jan 14, 2017
Messages
16,062
Yes 😁

Code:
Private Sub ComboName_AfterUpdate()

    If Me.ComboName ="Yes" Then Me.DateFieldControlName=Date()

End Sub
 

CJ_London

Super Moderator
Staff member
Local time
Today, 22:36
Joined
Feb 19, 2013
Messages
14,192
would help if you were consistent in what you tell us

combo box (the selections are Yes and No, with the default being No
The choices are N/A, No, and Yes (N/A is default)

So based on your second version I'm assuming the values are text and not numeric

if me.comboctrl="Yes" Then Me.YourDateFieldControl = Date()

or

Me.YourDateFieldControl = iif(me.comboctrl="Yes",Date(),null)

or

Code:
if me.comboctrl="Yes" Then
    Me.YourDateFieldControl = Date()
else
     Me.YourDateFieldControl = null
end if

depends what you want to happen if the user chooses yes, then changes their mind to no or n/a
 

Users who are viewing this thread

Top Bottom