Marc L
Marc L

Reputation: 887

Carry a variable in VBA for an user in MS Access

I am trying to create variable which would carry across all the users activities in MS Access.

So what I want to achieve is: The user opens the application and sets a region.

From that point onwards I want to be able to reference the region in my VBA commands that are triggered as the user moves between forms to limit data being displayed. How do I carry the variable through the various forms and queries or is it just a case of creating it as a parameter that is passed to each procedure as it is called?

Thanks

Upvotes: 1

Views: 341

Answers (2)

Dave Sexton
Dave Sexton

Reputation: 11188

Konrad's answer covers most options, I just wanted to add that as you are using Access you could always create a user to region mapping table and store the data there.

Upvotes: 1

Konrad
Konrad

Reputation: 18585

Following article on ozgrid variables in VBA have three scoping levels:

  1. Procedure-Level
  2. Module-Level
  3. Project-Level, Workbook Level, or Public Module-Level

It appears that the third one would be most relevant in the context of your request. You would define it like that:

Public SelectedRegion as Long

As an alternative approach, you may consider storing this selection in a file and reading the data from file. To introduce the relevant parts of the example available on the website:

myFile = "C:\test\geographical-coordinates.txt"
Open myFile For Input As #1
Do Until EOF(1)
    Line Input #1, textline
    text = text & textline
Loop
Close #1

Upvotes: 1

Related Questions