Set Combo's displayed value to a control box in a form

chuckcoleman

Registered User.
Local time
Today, 12:51
Joined
Aug 20, 2010
Messages
377
Hi, I have a Combo Box that has as it's Row Source only two choices:
1;"Spring Startup";2;"Winterize"
The width of the column widths are 0; 1.5, so you will only see Startup or Winterize
I have a Text Box called MonthNbr that has as it's control source: =IIf(DatePart("m",Date())<=7,1,2) Obviously that means if the month is less than or equal to July the number 1 is shown and if it's greater than 7 the number 2 is shown.

I want the Combo Box to default to show "Spring" if the Text Box MonthNbr is 1 and to show "Winterize" if the Text Box MonthNbr shows 2. I want the user to only click on the Combo Box if they want to change the displayed value.

I've researched this but haven't found an answer. Any ideas?
 
1. ensure that the Bound Column property is set to 1
2. in the form load event:

Code:
If DatePart("m", Date) <= 7 Then
    Me.Combo0.Value = 1
Else
    Me.Combo0.Value = 2
End If
 

Attachments

You realize that if you bind the combo to a field in the table your records will change depending on the current month. If you want the combo to default to those values (for a new record) you don't need the text box, just set the Default Value for the combo to your to IIf(Month(Date())<7,1,2).
To force it to load like that for each existing record then use Me.cboCombo=IIf(Month(Date())<7,1,2). in the Current event of the form.
Cheers,
Vlad
 
Thank you both. I added IIf(DatePart("m",Date())>=7,1,2) to the Default of the Combo Box and it worked. Actually, I had tried that before but I wasn't getting the result I wanted because I goofed. I had >=7,1,2 and it should have been >=7,2,1.

Thank you again.
 

Users who are viewing this thread

Back
Top Bottom