Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I have a very simple Access db with UserID, Office, Title,Show I want to Populate the list box with UserIDs that Match the Current user, also only add the user if they have Yes in the Show column.

I can get the current user but from there I'm just lost.

My thought process is

VB
Rows = Table.rows.count
i=1
Run loop i to rows
    if CurrentUser = Table(i,Column1(UserID))
       UserOffice = Table(i,Column2(office))
    end if
End loop
'Second loop
i=1
Loop i to rows
    If Table(i,Column2(office)) = UserOffice then
         If Table(i,Column4)= "Yes" Then
             listbox1.items.add Table(i,Column1(UserID))
         End if
    end if
end loop


Just interacting with the Table is frustrating to me at this point. I would normally hard code everything but there are too many changes to push out a new app every time someone moves offices. It has been a 15 years since I used VB so everything I know from VB is deprecated or lost to the sands of time.

Please help!

What I have tried:

I have tried few things but at this point. Everything I google I just don't really understand.
Posted
Updated 20-Feb-20 1:14am
Comments
Richard MacCutchan 19-Feb-20 4:05am    
How many UserIds are likely to match the current user? If it is more than one then there is something seriously odd about your design.
Member 14748582 19-Feb-20 15:44pm    
Just one UserID will match the Currentuser.
Richard MacCutchan 20-Feb-20 3:57am    
So why do you need a ListBox to show it?
Member 14748582 20-Feb-20 13:30pm    
Based on the Current users office I want the listbox to have a filtered list of Users in that office and only show the Agents or Managers.

Example:
Jane is a Clerk in Austin. When she opens the app she only sees the managers/Agents in the list or dropdown to select. If she chooses to see Houstin office from another drop down she will only see Managers/Agents from that office. But not the clerks. I'm sorry I was not clear with my request.
Richard MacCutchan 20-Feb-20 15:38pm    
I am not an expert in Access but it sounds like you need to:
- Get the Office that relates to the selected UserId
- Select all records "WHERE Office=foundOffice"

1 solution

Seems, you want to update one field depend on other field. I'd suggest to use MS Access parameterized query. For example:

SQL
PARAMETERS [pUserID] INTEGER, [pOffice] CHAR; 
UPDATE YourTableName 
SET YourTableName.Show = True 
WHERE YourTableName.UserID = [pUserID] AND YourTableName.Office = [pOffice];


For further details, please see:
PARAMETERS declaration (Microsoft Access SQL) | Microsoft Docs[^]
SQL data types (Access desktop database reference) | Microsoft Docs[^]
Use parameters in queries, forms, and reports - Access[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900