473,325 Members | 2,805 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,325 software developers and data experts.

Accessing global variables within a form

02.06.04
I need some help displaying a public variable on a form. The variable is
declared and initilazied in a module at startup (and declared Public). I
have verified this with a msgBox(dbprogram) call. When I try to display it
in the form in a text box I get a #Name? error instead. I was told I have to
write a function to display it. I wrote a public function in the startup
module to return the value of a given string variable. Below is the
declaration, the initialization and code for the function, and the way I
tried to display it.

Public dbprogram as string ' declared

dbprogram = "OMACS" initialized

The on enter code for frmSplash ' This is a splash screen for the program

Private Sub Form_Open(Cancel As Integer)
init_pub_const 'initializes the public variables
End Sub

txtProgramName is a text box, the Control Source reads:
=AcquireVarTxt(dbprogram)

The code for AcquireVarTxt() is

Public Function AcquireVarTxt(theVarStr As String) As String
Dim theVar As String
theVar = theVarStr
End Function

what am I doing wrong here.
Thanks Matt
Nov 13 '05 #1
2 1482
My guess is that an unhandled error is clearing the values of Global
variables.
Add error handling to your code to identify if this is the problem.

'---------------
' John Mishefske
'---------------
Matt Smolic wrote:

what am I doing wrong here.
Thanks Matt


Nov 13 '05 #2
bob
Matt Matt Matt.
Forget all the complex stuff, always try to simplify your code and
logic the Max. All you need to do is:
1. initialized the variable >>> dbprogram = "OMACS" >>> Which You've
done.
2. Assign the Value of the Varaible to your Text box \ Label or
Whatever Control. From the form Open or a Button click or any other
Event that you choose.
3. The Code for a text box or label.
Me.txtProgramName.Value = dbprogram
Me.lblProgramName.Caption = dbprogram
PS. You will need to Remove the Control Source {
=AcquireVarTxt(dbprogram) }from txtProgramName to make it an Unbound
Control.

Regards.
Deathbox from South Africa.

Nov 13 '05 #3

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

Similar topics

2
by: C Gillespie | last post by:
Dear All, I have 2 arrays var A1 = new Array(); A1 ="Y2"; var B1 = new Array(); B1 ="Y1"; B1 ="sink";
33
by: MLH | last post by:
I've read some posts indicating that having tons of GV's in an Access app is a bad idea. Personally, I love GVs and I use them (possibly abuse them) all the time for everything imaginable - have...
2
by: Earl Teigrob | last post by:
I am programming ASP.NET using C#. I have been accessing static variables accross my entire application but now need to change some of the static variables that are session specific to instance...
24
by: LP | last post by:
After a code review one coworker insisted that global are very dangerous. He didn't really give any solid reasons other than, "performance penalties", "hard to maintain", and "dangerous". I think...
2
by: Nathan Sokalski | last post by:
I would like to access variables and functions that I declare in the Global.asax.vb file. However, I am having trouble doing that. What does the declaration have to look like in the Global.asax.vb...
44
by: fabio | last post by:
Why? i' ve heard about this, the usage of global vars instead of locals is discouraged, but why? thx :)
12
by: Steve Blinkhorn | last post by:
Does anyone know of a way of accessing and modifying variables declared static within a function from outside that function? Please no homilies on why it's bad practice: the context is very...
18
by: Bruce | last post by:
When I do this: <input id="someName" type="text"> <script type="text/javascript"> alert(someName.nodeName); </script> Both IE6 and Firefox alert("INPUT"). Why isn't "someName" undefined?
14
by: ramprat | last post by:
Hi All, I currently need to store 3 variables to be used as global variables throughout my application. I need to record the username, their employee group and the task they are doing. The...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.