Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filtering an Access Form

Status
Not open for further replies.

codeWarrior456

Technical User
Oct 27, 2002
27
US
I have a database that is setup with a login screen. Users are prompted to login, and if they are successful the database stores 3 pieces of information about the user in global variables which I declared in a code module. What I am trying to do is when the user clicks on a button, I want the database to open the a form that is filtered based on the information stored in those variables. Is there a way to filter the form using a variable?

Illustration of problem:
1. User Logs in
2. Database stores users branch id in a global variable
3. User clicks on a form to edit branch information.
4. A branch form opens.
5. The branch form contains information for all the branches. However, the form should be filter to only display the branch information that is relevant to the user which is determined by using the branch id variable that was stored at login. (This is the part that I am stuck on).

Thanks in advance for any help/suggestions.
 
You know the branchID? A variable is set equal to branchID? (call it branch)
The form should only show relevant items?

In normal query design view make a query based on the table(s) of info required.

One field will already be set for the branchID, enter a branch ID into the criteria field, check with "!" that you are getting the result you want.
view-sql view and copy all to clipboard.

In vba on open form event for the branch form


dim sqlstr as string
sqlstr=" now paste from clipboard "

examine the string after "WHERE" and you will see the ID you put in, change that to " & branch & "

me.form.recordsource=sqlstr

Should now open the form to display only those records relevant to the variable "branch"

HTH

telephoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top