Combobox dependent on a criteria (1 Viewer)

CuriousGeo

Registered User.
Local time
Today, 16:24
Joined
Oct 15, 2012
Messages
59
Hello, I have a combobox on a form that is a list of usernames. It works in it's present state. However, what I would like to do is to change the list of names if the combobox is Null (no user has been selected). In that case, I would like the list to select the current user that has the database open. It would get the user ID from a hidden text box I have on the form. That way, the only name that would show in the combobox is the current user.
Otherwise, any previously selected username would still appear for other records where a name is already present in the combobox.

Current source of the combobox (cboInspectBy) is:

SELECT tblUsers.UniqueID_Users, tblUsers.fldUserName
FROM tblUsers
ORDER BY tblUsers.fldUserName;

The hidden field that contains the current user's UniqueID is called txtUserID

How would I write the criteria for this combobox?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:24
Joined
Oct 29, 2018
Messages
21,469
Hi. Assuming the current user is also in tblUsers, here's my guess:
Code:
SELECT tblUsers.UniqueID_Users, tblUsers.fldUserName
FROM tblUsers
[color=red]WHERE UniqueID_Users=Forms!FormName.HiddenTextboxName
  OR Forms!FormName.ComboboxName & "" <> ""[/color]
ORDER BY tblUsers.fldUserName;
Hope that helps...
 

CuriousGeo

Registered User.
Local time
Today, 16:24
Joined
Oct 15, 2012
Messages
59
Thank you DBguy, I tried your suggestion, but it didn't work as I was expecting. It still shows all the users in the combobox when that field is empty. Additionally, the query builder grid exhibits some strange behavior, it is splitting up the statement into two parts in the builder grid, even though I placed the whole statement into the SQL view

Field line:
[Forms]![frmIncomingBatch-NEW].[cboInspectBy] & ""

then in OR line it shows:
<>""
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:24
Joined
Oct 29, 2018
Messages
21,469
Thank you DBguy, I tried your suggestion, but it didn't work as I was expecting. It still shows all the users in the combobox when that field is empty. Additionally, the query builder grid exhibits some strange behavior, it is splitting up the statement into two parts in the builder grid, even though I placed the whole statement into the SQL view

Field line:
[Forms]![frmIncomingBatch-NEW].[cboInspectBy] & ""

then in OR line it shows:
<>""
Hi. Just another guess, since I can't see what's actually happening with your db, but it's probably not working as expected because you also need to requery the combobox every time you move from one record to another.

Right now, I imagine the combobox is behaving as you like based on the first record only. For example, if you empty out the combobox on the first record and then close and open the form again, do you still see all the users in the dropdown?
 

CuriousGeo

Registered User.
Local time
Today, 16:24
Joined
Oct 15, 2012
Messages
59
Hi. Just another guess, since I can't see what's actually happening with your db, but it's probably not working as expected because you also need to requery the combobox every time you move from one record to another.

Right now, I imagine the combobox is behaving as you like based on the first record only. For example, if you empty out the combobox on the first record and then close and open the form again, do you still see all the users in the dropdown?


You're right. I didn't think about adding in a Requery.
I added a requery and it works as it should! :)Thank you. If a name has already been entered, it stays the same. But when you go to a different record and the combo is blank, the user logged into the database is now the only name that shows in the combobox.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:24
Joined
Oct 29, 2018
Messages
21,469
You're right. I didn't think about adding in a Requery.
I added a requery and it works as it should! :)Thank you. If a name has already been entered, it stays the same. But when you go to a different record and the combo is blank, the user logged into the database is now the only name that shows in the combobox.
Hi. Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom