Combobox Default Value

LB79

Registered User.
Local time
Today, 23:47
Joined
Oct 26, 2007
Messages
505
Hi all,

Please could someone help me with this annoyance.
I have a combobox (CBO1) with the below rowsource (allowing me to have an “All” option).
Code:
[SIZE=3][COLOR=#000080][FONT=Arial]SELECT "All" AS [PIC Name], "*" AS [Ref] FROM tbl_REF_Users[/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000080][FONT=Arial]UNION SELECT tbl_REF_USERS.[PIC Name], tbl_REF_USERS.[PIC Name] AS Ref [/FONT][/COLOR][/SIZE]
[SIZE=3][COLOR=#000080][FONT=Arial]FROM tbl_REF_USERS GROUP BY tbl_REF_USERS.[PIC Name], tbl_REF_USERS.[PIC Name][/FONT][/COLOR][/SIZE]


I also have a public function (MyID) that retrieves the Windows user name.

I want the default value of CBO1 to be linked with MyID so that it automatically selects the current user but I cant seem to get it to do anything.

Thanks for any advice.
 
You should be able to use the function in the Default property of the combo.
I assume the return value of the current user is compatible with the combo's bound column.
 
Hi,
Yes they are both text. If i manually type in the value then it shows, but ref'ing to it in the default property returns blank.
 
I'm guessing you want the Combo box to change to the MyID when the form OPENS?
 
Yep. The list is of users which I want to default to the windows login.
 
Something like:
Code:
dim i as integer

for i = 0 to combo1.listcount - 1
    if combo1.column([COLOR=Red][B]1[/B][/COLOR]) = myid then
        combo1.selected(i) = true
        exit for
    end if
next
Look for the column where the User name appears in the combo box and change that value of 1 to that column number. Column numbers start from 0. So if the column is 4 then you put 3.
 
Thanks for the advice. I went a different way in the end.
I have a function in a module that gets the user name.
In the combobox default I just added =MyFunction() which picked out what I wanted.
 

Users who are viewing this thread

Back
Top Bottom