Full Version: Combo Box - Default Value Where 2 Columns In Play
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
cwac60
Hi Colleagues

Re Combo box - based on table tbl1

col1 col2

R Red
B Blue
W White
G Green


I can get col2 to display and use col1 to update tbl2 using
Column count 2
Column width 0;2.5 mm
Bound column 1

However I also want to set White as default - I tried both "W" and "White" as default value. Please let me know what
is missing OR should I use a list box instead?

Regards
cwac60

trapperalexander
since your bound column is 1 then the default value should be W

you told us you want the default value to be white and you told us what you did, but you did NOT tell us what the results were. ie, did you get an error message?

what happens when you open the form to a current record? what happens when you open the form to a new record?
Larry Larsen
Hi
You can use a small UDF (user defined function) to loop through each item of the combo and then set it's default..
eg:
CODE
Private Function SetComboColour()
Dim i          As Integer
    '/ Lets loop through the combo to find White..
    For i = 0 To cmbColour.ListCount - 1
    '/ if found set the combo..
        If Me.cmbColour.ItemData(i) = "White" Then
            Me.cmbColour = Me.cmbColour.ItemData(i)
        End If
    Next i
End Function


Note: Set the bound column to the actual colour column eg: (2)

And in the open event of the form simple call the above function..
CODE
Call SetComboColour


If your saving your selection then don't forget it's the primary value not the text that needs to be captured..
HTH's
thumbup.gif
cwac60
Hi Larry
Thank you for great idea, it certainly improves appearance and goes beyond what I had in mind was to 
to have word 'White' as default on drop down list. It appears that cmbTeam.Itemlist(3) in default property is the way to go.
Cheers
cwac60
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.