Create global variable and assign combo box value to that variable using button (1 Viewer)

ScoobsR

New member
Local time
Today, 10:51
Joined
Nov 20, 2015
Messages
7
Hi guys, ok I have a login screen, it is using a combobox (cmbUser) as the username field....

I want to make a global variable called strUser, when I select the user, enter the password the hit login I want the value held in cmbUser assigned to strUser so I can use this throughout my other forms to make my delete button visible using an if statement on each form load sub



From googling things I think I create the global variable using module like this.....?

Option Explicit

Public strUser As String



I already have code attached to the login button to validate the user, so I tried to attach........

strUser = cmbUser

To the code, obviously it never worked tho :confused:


I am pretty new to coding in access as u can probably tell and I would be grateful if anyone can help me with this (or tell me I'm barking up the wrong tree)
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 10:51
Joined
Aug 30, 2003
Messages
36,126
Where is

Public strUser As String

It would need to be in a standard module, not behind a form/report. Also make sure it isn't declared anywhere else.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 18:51
Joined
Jul 9, 2003
Messages
16,282
I create a custom database property to hold the user ID. See this thread for more details.

ACC2000: Custom DB Properties

Alternatively you can add a public variable to a hidden form which you keep open all the time. There may be other methods I am unaware of.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 10:51
Joined
Aug 30, 2003
Messages
36,126
You can also hide the login form rather than close it, and just refer to the combo from anywhere.
 

ScoobsR

New member
Local time
Today, 10:51
Joined
Nov 20, 2015
Messages
7
pbaldy - I created the strUser on the login form, but.....

the login form isn't being closed, so if I can just refer back to that it would be much easier - but again noob stuff from me here I'm afraid - I'm not sure how to use the value from the combo box in that form in another form to make the button visible ��

This is the first time I've had to code in access, with a bit of time/study/help i would like to think I'll get there with the syntax
 

ScoobsR

New member
Local time
Today, 10:51
Joined
Nov 20, 2015
Messages
7
Pbaldy - u r a prince among men,

That's probably kids stuff to u, but none the less - thank you very much for your help mate
����☺️��
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 10:51
Joined
Aug 30, 2003
Messages
36,126
Happy to help!
 

Users who are viewing this thread

Top Bottom