473,322 Members | 1,718 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,322 software developers and data experts.

How can I use a global variable in a

I have multiple forms that all run the same sub routine. In each form, I simply call the standard module that contains the sub routine. My sub routine contains a variable which gathers the form name of the open form and also the userName value of each form, like this:
Expand|Select|Wrap|Line Numbers
  1. Public userNameBC, frmName As String
  2. Public Sub Form_Load()
  3.         Set frmCurrentForm = Screen.ActiveForm
  4.         frmName = frmCurrentForm.Name
  5.         userNameBC = Forms(frmName).userName.Value
  6. End Sub
  7.  
The problem I'm having is the variable's that I set (frmName and userNameBC) are not working in my module. For example, if I test it by putting the following code in my module, the message box is blank.
Expand|Select|Wrap|Line Numbers
  1. MsgBox frmName & userNameBC
However, if I put the same message box code in my actual form, I can see the actual variables.

I can't figure out how to get get around this. Any ideas?
Jul 22 '13 #1
3 1257
Rabbit
12,516 Expert Mod 8TB
Well it looks like you declared you variables in your form module. If you have multiple forms all with the same variables declared, your non-form code module will not know which variable to use. You need to declare your variables only once, in the non-form code module.
Jul 22 '13 #2
@Rabbit

Ahhh! That makes perfect sense. I've been looking at this way toooooo long. Thanks for your help!
Ryan
Jul 22 '13 #3
Rabbit
12,516 Expert Mod 8TB
Not a problem, good luck with your project!
Jul 22 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bryan Parkoff | last post by:
….I would like to know which is the best optimization to use global variable or global struct. I always tell C/C++ Compiler to turn on optimization. ….I use underscore between first name and...
4
by: Dan Elliott | last post by:
Hello, Converting from a working C program to C++, I run into the following error: I have a header: (header.h) namespace shared{ ... struct X{ ...
1
by: ravinder thakur | last post by:
hi all experts, i am porting a project from c to the c++ framework. during the porting i have encounterd a where i have a static and a global variable with the same name. now what rules c...
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...
9
by: Shapper | last post by:
Hello, I am declaring a variable in my aspx.vb code as follows: Public Class catalogue Public productid As String Private Sub Page_Load ... I have an image button where I call the...
53
by: fdmfdmfdm | last post by:
This is an interview question and I gave out my answer here, could you please check for me? Q. What are the memory allocation for static variable in a function, an automatic variable and global...
8
by: yinglcs | last post by:
Hi, I read this article about global variable in c: http://www.phim.unibe.ch/comp_doc/c_manual/C/SYNTAX/glo_int_vars.html But I have a few questions 1. how can I declare the global variable...
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
20
by: teddysnips | last post by:
Weird. I have taken over responsibility for a legacy application, Access 2k3, split FE/BE. The client has reported a problem and I'm investigating. I didn't write the application. The...
2
by: RgeeK | last post by:
I'm seeing something which make me think I'm missing something about how global var's behave. I've defined a global string, right at the start of my .py file. outXMLfile = "abc" I define a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.