Update text field from ComboBox selection

dickohead

Registered User.
Local time
Tomorrow, 07:50
Joined
Dec 7, 2005
Messages
42
Hey Guys,

I have a combo box with entries that it pulls from a table.

Ie:

tblMonths
Month ________ Season
January ________ Summer
March _________ Autumn
November ______ Spring
December ______ Summer

Now in my form, when someone chooses January from my drop down list (the drop down list takes the values of tblMonths.Month), I have a text box that I want the Season to be displayed in - but I want it to pull the value from my tblMonths, as the data can change (months and seasons are just an example).

I could just use a set of nested if statements to say if it is equal to blah, display blah, but that's a bad way to do it!

I want it to say:

When the text box is January, pull the season that coresponds to January in tblMonths.

I'm sure there's a function or set of statements designed exactly for this, but I can't find them...

:)
 
This has been asked a thousand times -- the search function really does work in here -- but briefly, here's what you do.

1) The RecordSource for your ComboBox should be SELECT tblMonths.Season, tblMonths.Month FROM tblMonths;

2) The Column Count is set to 2.

3) The BoundColumn is set to 1.

4) The ColumnWidths is set to 0;

After that's done, you'll only see the months in your ComboBox, but the value of the ComboBox will be equal to the Season. Therefore:

txtSeason = cboMonths.Value

Each time cboMonths changes, the textbox will change to the value of the combobox, which is the season, because the BoundColumn is set to 1, and the first column, although invisible, is the season.
 
Cheers mate, I have been searching for a few hours, but did not realise that all those posts I was reading were relevant to me!

Woops!

I did try this though... kudos to me for trying! lol..

Code:
Private Sub lstMonth_Change()
Dim strMonth As String
Dim strSQL As String

strMonth = lstMonth.Value
strSQL = "SELECT tblMonths.Season FROM tblMonths WHERE tblMonths.Month = strMonth"
txtSeason.SetFocus
txtSeason.ControlSource = strSQL
lstMonth.SetFocus
End Sub

Thanks again mate!
 

Users who are viewing this thread

Back
Top Bottom