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 9 2110
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.
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***@REMOVEin stant-image.co.uk> wrote in message
news:ji******** *************@n ews-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
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********@NOS PAM.ntlworld.co m> wrote in message
news:5n******** ******@newsfep4-winn.server.ntl i.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***@REMOVEin stant-image.co.uk> wrote in message news:ji******** *************@n ews-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
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***@REMOVEin stant-image.co.uk> wrote in message
news:_5******** *************@n ews-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********@NOS PAM.ntlworld.co m> wrote in message news:5n******** ******@newsfep4-winn.server.ntl i.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***@REMOVEin stant-image.co.uk> wrote in message news:ji******** *************@n ews-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
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!
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
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
'-------------------------------
Peter Doering <ne**@doering.o rg> 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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 expected behavior).
What's the recommended/best way to persist these values through the post
process? I know I could set them to the request.form values of themselves,
so to speak...but I didn't know if there was a simpler/more efficient way.
...
|
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 words, their own definitions plus an example of how the word
is
used in practice. It'll be all client side with - cookies? to get
persistence so that the words won't
disappear on me each time the page is closed (which is what happened when I
|
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 writing an accounting application. I have a chart of
accounts in the form of a containment hierarchy. A GeneralLedger contains a
number of Accounts, and each of these Accounts can contain a Aubledger,
which contains its own Accounts, and so on. The...
|
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?
|
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 username and password again
We have previously stored these in a session variable (encrypted) and
retrieved from their - but are worried about the impact on performance if the
number of users increases.
Had thought about cookies but worried...
| |
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 properly because it displays in the
document.write method.
Create a simple page and paste the below in the code-behind (ASP.NET
1.1-SP1)
using System;
|
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 automatically if the data doesn't change. But if records have
been added or deleted then it looks as if some code is necessary: I've done
this by using GridView.SelectedValue to get the key value of the currently
selected Row and then by itterating...
|
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.
Here's my problem: I can't get design-time property values to persist. Here
is my property declaration:
|
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 is that the user wants to
know which page they are currently on and therefore I need to highlight
the selected node. The problem is I lose state whenever the user selects
a node and is redirected to another page.
Thanks in advance
|
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 results will get populated in an MSHFlexGrid.
3. There will be a button at the bottom captioning "Export to excel" clicking which shoud generate an excel file with the data contained in the grid.
4. User must not be able to copy the data from the...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |