Updating a record based on a combo selection

ChrisSedgwick

Registered User.
Local time
Today, 18:44
Joined
Jan 8, 2015
Messages
119
Hi,

I want to update a record when I select a specific option from a combo box in a form.

The concept seems simple, its the code that I struggle with...

I have a combo box in a form that has two options -- "Won" or "Lost"
I have a field in my table called "DateWon"
When I select "Won" from the combo I want the system date to be input into the "DateWon" field in my table.

Sounds simple... I'm just struggling to make it happen with no VBA experience... Just to give you a background to what I've tried (Spare me the embarrassment if I'm miles out) here's what I did...

In my form I created a text box and in the control source input this code:

Code:
=IIf([Combo526]="Won",[Text615]=Date(),")

Haven't named them well, however was trying to get it to work first.

Am I anywhere close or miles out? Either way could someone offer some guidance? Be gentle, still learning!

Thanks in advance...

Chris. :)
 
That won't work as your combo box value hasn't been set when the form is loaded.
You need to run some simple code on the after update event of the combo box.

Code:
If me.combo526 = "Won" Then
   Text615 = Date()
End If

Obviously you can get cleverer and maybe not allow the value in tetx615 to be changed if there is already a value in it;

Code:
If Me.combo526 = "Won"  AND IsNull(Me.text615) Then
    Text615 = Date()
Else
    msgbox "There is already a Won date!"
End If
 
Minty,

Wow, thanks! Seems too simple when you see it in front of you, however can be frustrating feeling you're miles away from the end results!

Huge help, thanks!

Chris. :)
 

Users who are viewing this thread

Back
Top Bottom