473,396 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Persisting value

Anyone help a beginner at VBA please?

I am trying to find a way to use a variable throughout an application.

I want to take the value from a log-in form (the user) and use it in most
forms that user opens.

I have tried a number of things but none seem to work

TIA

Clive
Nov 12 '05 #1
9 2097
Clive,
I am trying to find a way to use a variable throughout an application. I want to take the value from a log-in form (the user) and use it in most
forms that user opens.


You have to declare the variable in a module(!) as Public:

Public YourUserID As String

HTH - Peter

--
No mails please.
Nov 12 '05 #2
One way would be to leave the log in form open all the time so the value can
always be retrieved directly from the form. If the "OK" button on the form
hides the form rather than closing it then this should work. To simplyfy the
code you could create a simple function that looks up the form value, and
then just use the function name whenever you need the value.

"Clive Moss" <cl***@REMOVEinstant-image.co.uk> wrote in message
news:ji*********************@news-text.cableinet.net...
Anyone help a beginner at VBA please?

I am trying to find a way to use a variable throughout an application.

I want to take the value from a log-in form (the user) and use it in most
forms that user opens.

I have tried a number of things but none seem to work

TIA

Clive

Nov 12 '05 #3
Thanks Andrew - I had tried a version of that idea but I must have done
something else wrong because it didn't work

I'll try it again after dinner!

Clive

"Andrew Smith" <an********@NOSPAM.ntlworld.com> wrote in message
news:5n**************@newsfep4-winn.server.ntli.net...
One way would be to leave the log in form open all the time so the value can always be retrieved directly from the form. If the "OK" button on the form
hides the form rather than closing it then this should work. To simplyfy the code you could create a simple function that looks up the form value, and
then just use the function name whenever you need the value.

"Clive Moss" <cl***@REMOVEinstant-image.co.uk> wrote in message
news:ji*********************@news-text.cableinet.net...
Anyone help a beginner at VBA please?

I am trying to find a way to use a variable throughout an application.

I want to take the value from a log-in form (the user) and use it in most forms that user opens.

I have tried a number of things but none seem to work

TIA

Clive


Nov 12 '05 #4
Thanks again - Just tried it out and it works fine - I was doing something
really stupid before which is too embarrassing and long winded to explain

Clive

"Clive Moss" <cl***@REMOVEinstant-image.co.uk> wrote in message
news:_5*********************@news-text.cableinet.net...
Thanks Andrew - I had tried a version of that idea but I must have done
something else wrong because it didn't work

I'll try it again after dinner!

Clive

"Andrew Smith" <an********@NOSPAM.ntlworld.com> wrote in message
news:5n**************@newsfep4-winn.server.ntli.net...
One way would be to leave the log in form open all the time so the value

can
always be retrieved directly from the form. If the "OK" button on the form
hides the form rather than closing it then this should work. To simplyfy

the
code you could create a simple function that looks up the form value, and then just use the function name whenever you need the value.

"Clive Moss" <cl***@REMOVEinstant-image.co.uk> wrote in message
news:ji*********************@news-text.cableinet.net...
Anyone help a beginner at VBA please?

I am trying to find a way to use a variable throughout an application.

I want to take the value from a log-in form (the user) and use it in

most forms that user opens.

I have tried a number of things but none seem to work

TIA

Clive



Nov 12 '05 #5
Leaving the login form open is a good method. Should you need to have
it closed, or if a user closes it, another method is to store the
values(s) you want to Global (Public) variables as the form closes. I
use this method for exactly the same reason, to store login information
and it has worked well with all my apps. Another alternative is to
write the value(s) to a temp file (.txt) and read the file when needed.
Look for and delete the file at application start up as well as at
application close to ensure the file is created at each application
start.

MPP
Lanexa, Virginia

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #6
I like Peter's idea. If you have to persist it across sessions
(open/close of database) then you should look into writing it to
either a table or a custom database property. Then retrieve it when
the database opens like Peter said.

HTH,
Village Idiot
Nov 12 '05 #7
Clive Moss wrote:
Thanks again - Just tried it out and it works fine - I was doing something
really stupid before which is too embarrassing and long winded to explain

Clive


Unhandled errors (or more exactly - the user resetting code execution) will
reset (or clear) global variables. Perhaps that is what happened to you?
Make sure you have error handlers in your code procedures.

Save the value in a table if you need persistence or consider classes to
prevent this type of problem.

--
'-------------------------------
' John Mishefske
'-------------------------------

Nov 12 '05 #8
Peter Doering <ne**@doering.org> wrote:
You have to declare the variable in a module(!) as Public:

Public YourUserID As String


Trouble is if you're in the middle of running some code, hit a breakpoint or
whatever, and then stop the code you lose all these variables.

Thus I use an always open hidden form to store such variables in.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Nov 12 '05 #9
Tony,
Public YourUserID As String
Trouble is if you're in the middle of running some code, hit a breakpoint or
whatever, and then stop the code you lose all these variables.
Sure, that's what I want. I see it as a feature, not a bug. What's wrong
with the user having to login again after a program failure?

Your statement is true also for all other global variables (which should be
avoided in general, I know). Perfect for storage of passwords, aren't they.
Thus I use an always open hidden form to store such variables in.


There's no argument against this method either (unless one prefers global
variables ;-)

Peter

--
No mails please.
Nov 12 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: James Baker | last post by:
I have a form that has a dropdown list that will cause a post to the same page when it's changed. The problem I'm running into is that all of the controls reset to their default values (obviously...
2
by: Citoyen du Monde | last post by:
Trying to get some ideas on a simple javascript project (to teach myself the language). I want to develop a client-side vocabulary practice application that would allow users to enter their own...
4
by: Dave Veeneman | last post by:
When does serializing objects make more sense than persisting them to a database? I'm new to object serialization, and I'm trying to get a feel for when to use it. Here is an example: I'm...
1
by: lim | last post by:
What is the possible error that occurs when the Page_load event is not triggered during execution. In my page there's some basic server control. Is there any loops holes?
19
by: Siobhan | last post by:
Hi What is the recommended way to store a user's database credentials across the pages of a web application so that each time the database is accessed the system doesn't have to ask them for their...
2
by: xenophon | last post by:
I added a Hidden Form Field to a form in the code behind. The value is being set in JavaScript client-side, but it is not persisting to the server in the PostBack. I know the value is being set...
5
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens...
1
by: David Veeneman | last post by:
I'm backporting a component to .NET 1.x, and it required me to use a custom collection, StringList, instead of List<string>. StringList is derived from CollectionBase and is marked serializable. ...
1
by: Nikron | last post by:
Hi, I'm having an issue with the ASP.NET 2.0 Treeview control and persisting its' state accross requests. My Control is embedded within a master page and is used for site navigation. My problem...
16
by: vikas000000a | last post by:
Hello all, I am creating a report generation program with VB 6.0 as front-end and Oracle 10i as back-end. My reqiurements are 1. User will query the database through the front-end. 2. The...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.