Newbie to VBA - Group Variables and Forms

T

Tom

Hi

Please keep your answers simple as I am cribbing code from ng's whilst
trying to learn VBA.

I have a 'client' database application that requires the user to log in and
provide a password. This is achieved using a start-up form that looks up the
userid and password in a table, and if OK, passes the user on to a form
(frmENTRY). So far, so good.

I want to be able to store the userid as a global variable so that it can be
used by any other forms at a later date, and I cannot get it to work.

So far, I have created a module called 'Global' with the following code

===================

Option Compare Database
Option Explicit

'GLOBAL DECLARATIONS, CONSTANTS AND VARIABLES

Global User_ID As String

==================

I want to be able, for example, to open form frmENTRY and display a textbox
called [USER_LOGGED_IN] that, on opening the form, displays the content of
the global variable 'User_ID'.

Can someone tell me, in the simplest of terms, what code I need to put
behind the 'On Open' control of frmENTRY ?

Many thanks - I have struggling with this for a couple of days and am
getting nowhere.

Regards

Tom
 
J

JohnFol

There are several ways, such as

On the OnOpen of the form
Me![USER_LOGGED_IN] = User_ID


or use the OpenArgs if you are just passing the value to a new form, ie
DoCmd.OpenForm "frmENTRY", , , , , , txtBoxWhereNameEntered

Then on the frmENTRY do

Private Sub Form_Open(Cancel As Integer)
Me![USER_LOGGED_IN] = Me.OpenArgs
End Sub


Regards
 
T

Tom

Thanks for the quick reply John.

Your first suggestion is basically one that I have already tried. I coded it
as follows.

===========================

Private Sub Form_Open(Cancel As Integer)
Me![USER_LOGGED_IN] = User_ID
End Sub

==========================

It fails with the following error

"Run-time error 2448
You can't assign a value to this object"

How do I prove the global variable has picked up the value?

Regards

Tom

JohnFol said:
There are several ways, such as

On the OnOpen of the form
Me![USER_LOGGED_IN] = User_ID


or use the OpenArgs if you are just passing the value to a new form, ie
DoCmd.OpenForm "frmENTRY", , , , , , txtBoxWhereNameEntered

Then on the frmENTRY do

Private Sub Form_Open(Cancel As Integer)
Me![USER_LOGGED_IN] = Me.OpenArgs
End Sub


Regards


Tom said:
Hi

Please keep your answers simple as I am cribbing code from ng's whilst
trying to learn VBA.

I have a 'client' database application that requires the user to log in
and
provide a password. This is achieved using a start-up form that looks up
the
userid and password in a table, and if OK, passes the user on to a form
(frmENTRY). So far, so good.

I want to be able to store the userid as a global variable so that it can
be
used by any other forms at a later date, and I cannot get it to work.

So far, I have created a module called 'Global' with the following code

===================

Option Compare Database
Option Explicit

'GLOBAL DECLARATIONS, CONSTANTS AND VARIABLES

Global User_ID As String

==================

I want to be able, for example, to open form frmENTRY and display a
textbox
called [USER_LOGGED_IN] that, on opening the form, displays the content of
the global variable 'User_ID'.

Can someone tell me, in the simplest of terms, what code I need to put
behind the 'On Open' control of frmENTRY ?

Many thanks - I have struggling with this for a couple of days and am
getting nowhere.

Regards

Tom
 
I

Immanuel Sibero

Tom,

Two things:

- You should avoid using Global as your module name. It's a reserved word.
You could try vbaGlobal or mdlGlobal, etc.
- What you're doing is reinventing the wheel. Access User Level security
would take care of this. It carries a steep learning curve but the time
you're spending fighting with it and reinventing it could've been used to
learn it (the Access User Level security).


You can start with:
http://www.jmwild.com/Accesssecurity.htm


HTH,
Immanuel Sibero
 
T

Tom

Hi Immanuel

The module was originally called 'Globals' but I changed it in desparation
to Global in the naive hope that this was the problem ;-).

I confess I have not read up on Access User Level security. As a novice I
cannot comment, but I have been given the impression it was not that strong.
Also, I am not sure it is appropriate to this application. Let me explain:

This is a client application that will be run on about a dozen PCs. The idea
is that the users in question can wander around our factory and log into
this application at any PC with it loaded, without logging on to the PC
itself, as that will already be logged in for its full-time user. Any data
created within this database will have an audit trail record copied to a
back-end server, showing the PC Name, PC Login Name, Administrator IT (the
one I am having the problem with), the date and time, and field values both
before and after changes were made.

Regards

Tom


Immanuel Sibero said:
Tom,

Two things:

- You should avoid using Global as your module name. It's a reserved word.
You could try vbaGlobal or mdlGlobal, etc.
- What you're doing is reinventing the wheel. Access User Level security
would take care of this. It carries a steep learning curve but the time
you're spending fighting with it and reinventing it could've been used to
learn it (the Access User Level security).


You can start with:
http://www.jmwild.com/Accesssecurity.htm


HTH,
Immanuel Sibero




Tom said:
Hi

Please keep your answers simple as I am cribbing code from ng's whilst
trying to learn VBA.

I have a 'client' database application that requires the user to log in and
provide a password. This is achieved using a start-up form that looks up the
userid and password in a table, and if OK, passes the user on to a form
(frmENTRY). So far, so good.

I want to be able to store the userid as a global variable so that it
can
be
used by any other forms at a later date, and I cannot get it to work.

So far, I have created a module called 'Global' with the following code

===================

Option Compare Database
Option Explicit

'GLOBAL DECLARATIONS, CONSTANTS AND VARIABLES

Global User_ID As String

==================

I want to be able, for example, to open form frmENTRY and display a textbox
called [USER_LOGGED_IN] that, on opening the form, displays the content of
the global variable 'User_ID'.

Can someone tell me, in the simplest of terms, what code I need to put
behind the 'On Open' control of frmENTRY ?

Many thanks - I have struggling with this for a couple of days and am
getting nowhere.

Regards

Tom
 
T

Tom

Hi John

Your second suggestion came up with the same problem but it is now fixed as
I seem to have left some garbage in the criteria box on the text box in
frmENTRY.

Thanks for your help.

Tom

Tom said:
Thanks for the quick reply John.

Your first suggestion is basically one that I have already tried. I coded it
as follows.

===========================

Private Sub Form_Open(Cancel As Integer)
Me![USER_LOGGED_IN] = User_ID
End Sub

==========================

It fails with the following error

"Run-time error 2448
You can't assign a value to this object"

How do I prove the global variable has picked up the value?

Regards

Tom

JohnFol said:
There are several ways, such as

On the OnOpen of the form
Me![USER_LOGGED_IN] = User_ID


or use the OpenArgs if you are just passing the value to a new form, ie
DoCmd.OpenForm "frmENTRY", , , , , , txtBoxWhereNameEntered

Then on the frmENTRY do

Private Sub Form_Open(Cancel As Integer)
Me![USER_LOGGED_IN] = Me.OpenArgs
End Sub


Regards


Tom said:
Hi

Please keep your answers simple as I am cribbing code from ng's whilst
trying to learn VBA.

I have a 'client' database application that requires the user to log in
and
provide a password. This is achieved using a start-up form that looks up
the
userid and password in a table, and if OK, passes the user on to a form
(frmENTRY). So far, so good.

I want to be able to store the userid as a global variable so that it can
be
used by any other forms at a later date, and I cannot get it to work.

So far, I have created a module called 'Global' with the following code

===================

Option Compare Database
Option Explicit

'GLOBAL DECLARATIONS, CONSTANTS AND VARIABLES

Global User_ID As String

==================

I want to be able, for example, to open form frmENTRY and display a
textbox
called [USER_LOGGED_IN] that, on opening the form, displays the
content
 
U

User

Try:
Public User_ID As String

Nothing needs be done in the "On_Open" as any form code will referencing
"User_ID" will pick up the global instance as long as there is no
naming/scope conflict.

Tom said:
Hi Immanuel

The module was originally called 'Globals' but I changed it in desparation
to Global in the naive hope that this was the problem ;-).

I confess I have not read up on Access User Level security. As a novice I
cannot comment, but I have been given the impression it was not that strong.
Also, I am not sure it is appropriate to this application. Let me explain:

This is a client application that will be run on about a dozen PCs. The idea
is that the users in question can wander around our factory and log into
this application at any PC with it loaded, without logging on to the PC
itself, as that will already be logged in for its full-time user. Any data
created within this database will have an audit trail record copied to a
back-end server, showing the PC Name, PC Login Name, Administrator IT (the
one I am having the problem with), the date and time, and field values both
before and after changes were made.

Regards

Tom


Immanuel Sibero said:
Tom,

Two things:

- You should avoid using Global as your module name. It's a reserved word.
You could try vbaGlobal or mdlGlobal, etc.
- What you're doing is reinventing the wheel. Access User Level security
would take care of this. It carries a steep learning curve but the time
you're spending fighting with it and reinventing it could've been used to
learn it (the Access User Level security).


You can start with:
http://www.jmwild.com/Accesssecurity.htm


HTH,
Immanuel Sibero




Tom said:
Hi

Please keep your answers simple as I am cribbing code from ng's whilst
trying to learn VBA.

I have a 'client' database application that requires the user to log
in
and
provide a password. This is achieved using a start-up form that looks
up
the
userid and password in a table, and if OK, passes the user on to a form
(frmENTRY). So far, so good.

I want to be able to store the userid as a global variable so that it
can
be
used by any other forms at a later date, and I cannot get it to work.

So far, I have created a module called 'Global' with the following code

===================

Option Compare Database
Option Explicit

'GLOBAL DECLARATIONS, CONSTANTS AND VARIABLES

Global User_ID As String

==================

I want to be able, for example, to open form frmENTRY and display a textbox
called [USER_LOGGED_IN] that, on opening the form, displays the
content
 
I

Immanuel Sibero

Hi Tom,
I assume you have your issue with the global / public variable resolved.


Regarding the User Level security:
cannot comment, but I have been given the impression it was not that
strong.
Access User Level security is as strong as any file-based database
application can be. It is not as strong as a client server base such as SQL
server.
Also, I am not sure it is appropriate to this application. Let me
explain:.....
The use Access User Level security can easily be implemented in your case.
Of course, you can certainly leave the design the way it is currently. From
your description the emphasis of the client application seems to be on audit
trail, not on security since it is definitely not secure. Anyone can
probably open the app while pressing down the Shift key and bypass the
frmENTRY. Anyone can probably link to any of the tables from another .mdb.


Immanuel Sibero




Tom said:
Hi Immanuel

The module was originally called 'Globals' but I changed it in desparation
to Global in the naive hope that this was the problem ;-).

I confess I have not read up on Access User Level security. As a novice I
cannot comment, but I have been given the impression it was not that strong.
Also, I am not sure it is appropriate to this application. Let me explain:

This is a client application that will be run on about a dozen PCs. The idea
is that the users in question can wander around our factory and log into
this application at any PC with it loaded, without logging on to the PC
itself, as that will already be logged in for its full-time user. Any data
created within this database will have an audit trail record copied to a
back-end server, showing the PC Name, PC Login Name, Administrator IT (the
one I am having the problem with), the date and time, and field values both
before and after changes were made.

Regards

Tom


Immanuel Sibero said:
Tom,

Two things:

- You should avoid using Global as your module name. It's a reserved word.
You could try vbaGlobal or mdlGlobal, etc.
- What you're doing is reinventing the wheel. Access User Level security
would take care of this. It carries a steep learning curve but the time
you're spending fighting with it and reinventing it could've been used to
learn it (the Access User Level security).


You can start with:
http://www.jmwild.com/Accesssecurity.htm


HTH,
Immanuel Sibero




Tom said:
Hi

Please keep your answers simple as I am cribbing code from ng's whilst
trying to learn VBA.

I have a 'client' database application that requires the user to log
in
and
provide a password. This is achieved using a start-up form that looks
up
the
userid and password in a table, and if OK, passes the user on to a form
(frmENTRY). So far, so good.

I want to be able to store the userid as a global variable so that it
can
be
used by any other forms at a later date, and I cannot get it to work.

So far, I have created a module called 'Global' with the following code

===================

Option Compare Database
Option Explicit

'GLOBAL DECLARATIONS, CONSTANTS AND VARIABLES

Global User_ID As String

==================

I want to be able, for example, to open form frmENTRY and display a textbox
called [USER_LOGGED_IN] that, on opening the form, displays the
content
 
T

Tom

Hi Immanuel

You have given me some things to ponder here. Yes, I have got round the
problem in the short term. As far as security of the system is concerned,
our users are, in the main, machine operators who are not going to find
using a PC at all easy, so the likelihood of anyone trying to hack the
tables is slim. Also, I aim to convert the client side to a run-time
application, with the server-side tables converted to MSDE. This should make
it harder for anyone to read tables on the fly. I will look further into
Access' own security though.

Thanks for the advice.

Regards

Tom
Immanuel Sibero said:
Hi Tom,
I assume you have your issue with the global / public variable resolved.


Regarding the User Level security:
cannot comment, but I have been given the impression it was not that
strong.
Access User Level security is as strong as any file-based database
application can be. It is not as strong as a client server base such as
SQL
server.
Also, I am not sure it is appropriate to this application. Let me
explain:.....
The use Access User Level security can easily be implemented in your case.
Of course, you can certainly leave the design the way it is currently.
From
your description the emphasis of the client application seems to be on
audit
trail, not on security since it is definitely not secure. Anyone can
probably open the app while pressing down the Shift key and bypass the
frmENTRY. Anyone can probably link to any of the tables from another .mdb.


Immanuel Sibero




Tom said:
Hi Immanuel

The module was originally called 'Globals' but I changed it in
desparation
to Global in the naive hope that this was the problem ;-).

I confess I have not read up on Access User Level security. As a novice I
cannot comment, but I have been given the impression it was not that strong.
Also, I am not sure it is appropriate to this application. Let me
explain:

This is a client application that will be run on about a dozen PCs. The idea
is that the users in question can wander around our factory and log into
this application at any PC with it loaded, without logging on to the PC
itself, as that will already be logged in for its full-time user. Any
data
created within this database will have an audit trail record copied to a
back-end server, showing the PC Name, PC Login Name, Administrator IT
(the
one I am having the problem with), the date and time, and field values both
before and after changes were made.

Regards

Tom


Immanuel Sibero said:
Tom,

Two things:

- You should avoid using Global as your module name. It's a reserved word.
You could try vbaGlobal or mdlGlobal, etc.
- What you're doing is reinventing the wheel. Access User Level
security
would take care of this. It carries a steep learning curve but the time
you're spending fighting with it and reinventing it could've been used to
learn it (the Access User Level security).


You can start with:
http://www.jmwild.com/Accesssecurity.htm


HTH,
Immanuel Sibero




Hi

Please keep your answers simple as I am cribbing code from ng's
whilst
trying to learn VBA.

I have a 'client' database application that requires the user to log in
and
provide a password. This is achieved using a start-up form that looks up
the
userid and password in a table, and if OK, passes the user on to a form
(frmENTRY). So far, so good.

I want to be able to store the userid as a global variable so that it can
be
used by any other forms at a later date, and I cannot get it to work.

So far, I have created a module called 'Global' with the following code

===================

Option Compare Database
Option Explicit

'GLOBAL DECLARATIONS, CONSTANTS AND VARIABLES

Global User_ID As String

==================

I want to be able, for example, to open form frmENTRY and display a
textbox
called [USER_LOGGED_IN] that, on opening the form, displays the
content
of
the global variable 'User_ID'.

Can someone tell me, in the simplest of terms, what code I need to
put
behind the 'On Open' control of frmENTRY ?

Many thanks - I have struggling with this for a couple of days and am
getting nowhere.

Regards

Tom
 
I

Immanuel Sibero

Good luck to you, Tom.
This newsgroup is filled with experts that I have benefited from, so check
back often, I'm sure you can benefit from them too.

Immanuel Sibero



Tom said:
Hi Immanuel

You have given me some things to ponder here. Yes, I have got round the
problem in the short term. As far as security of the system is concerned,
our users are, in the main, machine operators who are not going to find
using a PC at all easy, so the likelihood of anyone trying to hack the
tables is slim. Also, I aim to convert the client side to a run-time
application, with the server-side tables converted to MSDE. This should make
it harder for anyone to read tables on the fly. I will look further into
Access' own security though.

Thanks for the advice.

Regards

Tom
Immanuel Sibero said:
Hi Tom,
I assume you have your issue with the global / public variable resolved.


Regarding the User Level security:
cannot comment, but I have been given the impression it was not that
strong.
Access User Level security is as strong as any file-based database
application can be. It is not as strong as a client server base such as
SQL
server.
Also, I am not sure it is appropriate to this application. Let me
explain:.....
The use Access User Level security can easily be implemented in your case.
Of course, you can certainly leave the design the way it is currently.
From
your description the emphasis of the client application seems to be on
audit
trail, not on security since it is definitely not secure. Anyone can
probably open the app while pressing down the Shift key and bypass the
frmENTRY. Anyone can probably link to any of the tables from another ..mdb.


Immanuel Sibero




Tom said:
Hi Immanuel

The module was originally called 'Globals' but I changed it in
desparation
to Global in the naive hope that this was the problem ;-).

I confess I have not read up on Access User Level security. As a novice I
cannot comment, but I have been given the impression it was not that strong.
Also, I am not sure it is appropriate to this application. Let me
explain:

This is a client application that will be run on about a dozen PCs. The idea
is that the users in question can wander around our factory and log into
this application at any PC with it loaded, without logging on to the PC
itself, as that will already be logged in for its full-time user. Any
data
created within this database will have an audit trail record copied to a
back-end server, showing the PC Name, PC Login Name, Administrator IT
(the
one I am having the problem with), the date and time, and field values both
before and after changes were made.

Regards

Tom



Tom,

Two things:

- You should avoid using Global as your module name. It's a reserved word.
You could try vbaGlobal or mdlGlobal, etc.
- What you're doing is reinventing the wheel. Access User Level
security
would take care of this. It carries a steep learning curve but the time
you're spending fighting with it and reinventing it could've been
used
to
learn it (the Access User Level security).


You can start with:
http://www.jmwild.com/Accesssecurity.htm


HTH,
Immanuel Sibero




Hi

Please keep your answers simple as I am cribbing code from ng's
whilst
trying to learn VBA.

I have a 'client' database application that requires the user to
log
in
and
provide a password. This is achieved using a start-up form that
looks
up
the
userid and password in a table, and if OK, passes the user on to a form
(frmENTRY). So far, so good.

I want to be able to store the userid as a global variable so that it
can
be
used by any other forms at a later date, and I cannot get it to work.

So far, I have created a module called 'Global' with the following code

===================

Option Compare Database
Option Explicit

'GLOBAL DECLARATIONS, CONSTANTS AND VARIABLES

Global User_ID As String

==================

I want to be able, for example, to open form frmENTRY and display a
textbox
called [USER_LOGGED_IN] that, on opening the form, displays the content
of
the global variable 'User_ID'.

Can someone tell me, in the simplest of terms, what code I need to
put
behind the 'On Open' control of frmENTRY ?

Many thanks - I have struggling with this for a couple of days and am
getting nowhere.

Regards

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top