| re: Combo Box inital value to display
"Dave N" <nelsondavea@johndeere.com> wrote in message
news:3fe08914$1@news1.dpn.deere.com...[color=blue]
> I have a combo box that displays the names of all the users in my "Users"
> table. I set the RowSource to a Query from the "User" and "Project"[/color]
tables.[color=blue]
>
> I can select any name from the list and that name comes up in the combo[/color]
box[color=blue]
> on the form. Everything works fine this way I just want to automatically
> put the user name in the combo box display.
>
> Is there a way to automate displaying a name in the combo box without[/color]
having[color=blue]
> to use the drop down.
>
> I get the current users ID number by using an API call (thanks to Ken[/color]
Getz).[color=blue]
>
> After the call returns the ID I take that value and place it in a hidden
> textbox on my main form.
>
> ????? How do I get the name from the "User" table that matches this ID[/color]
to[color=blue]
> displayed in the combo box? The combo box is already populated with[/color]
names.[color=blue]
> ?????
>
> I tried using the RowSource property with a select statement but that only
> limited the list to the user name that matched the ID. It did not display
> it in the combo box though, you still had to select it. I figured that[/color]
was[color=blue]
> because the RowSource property only puts data in the rows and does not do
> the displaying of the data.
>
> I do not want to lose the list of users, I just want to display the logged
> in one.
>
> I use the ID to filter the records in a list box on the form and other
> things.
>
> Thanks.
>
> Dave N
>
>[/color]
You can do this a few different ways:
#1 - If your combo box Row Source query has both ID and Username (i.e
Select ID, Name From Users) and the ID is hidden, you can simply assign the
User ID to the combo box.
Ex.
Sub Form_OnCurrent()
Combobox1 = HiddenIDControl
End Sub
#2 - If you ONLY want to show the user who is currently logged on, you can
also alter your rowsource query a little
"Select [ID], [Name] From [UsersTable] Where [ID]=" &
Forms![YourFormName]![YouHiddenControlName]
Hope that helps... |