473,469 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to use global variables in VBA?

3 New Member
Hello, trying to implement a global variable iTable that I can increment/decrement and use its value anytime needed.

1. globalvariables module:
Expand|Select|Wrap|Line Numbers
  1. Global iTable As Integer
2. One of my subs that change its value:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtProduct1_Enter()
  2.     iTable = 3
  3. End Sub
3. Sub where I call it with a Select Case
Expand|Select|Wrap|Line Numbers
  1. Private Sub populateTxtOnEnter(ByVal copy As String, ByVal iTable As Integer)
  2.     Select Case iTable
  3.     Case 1
  4.         MsgBox "ERROR"
  5.         txtClient.Value = copy
  6.         textTicket.SetFocus
  7.     Case 2
  8.         textTicket.Value = copy
  9.         txtProduct1.SetFocus
  10.     Case 3
  11.         txtProduct1.Value = copy
  12.         'txtSize1.SetFocus
  13.     Case 4
  14.         txtSize1.Value = copy
  15.         txtQuantity1.SetFocus
  16.     End Select   
  17. End Sub

Now, altough I enter txtProduct1 TextBox, and my iTable is changed to 3, when the code reachs the Select Case, it always goes Case 1 and displays "ERROR" MsgBox that I created. I ask you why?

I tried a MsgBox on txtProduct1_Enter and it gave me iTable = 3.
Nov 19 '14 #1

✓ answered by Satsulima

Solved. No problems on global variables, other subs are calling one that puts iTable back on 1, hence the problem.

2 1044
Satsulima
3 New Member
How can its value change back to 1? Please help
Nov 19 '14 #2
Satsulima
3 New Member
Solved. No problems on global variables, other subs are calling one that puts iTable back on 1, hence the problem.
Nov 19 '14 #3

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

Similar topics

1
by: mark4asp | last post by:
What are the best methods for using global constants and variables? I've noticed that many people put all global constants in a file and include that file on every page. This is the best way of...
10
by: Matt | last post by:
Greetings, What are people's thoughts on global variables in C++? Why are we taught not to use them in programming? Is it true that if you are running two copies of the C program one copy can...
5
by: Richard A. DeVenezia | last post by:
Dear Experts: Suppose I have global variables: x1, x2, x3 and I have a function that needs to assign a value to a new global variable x4 something like function foo () { count = 0;
2
by: Patient Guy | last post by:
I have a library of functions representing a filesystem interface (essentially a file selection interface, to be used in opening/reading/writing/closing files). Heavily scripted HTML document...
17
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm...
7
by: Michael | last post by:
Hi newsgroup, as the subject indicates I am looking for an advice using global variables. I am not if this problem is more about style then C. If its wrong in thi group, sorry. So I have a...
7
by: zeecanvas | last post by:
Hi, First of all: Yes, I know global variables are bad, but I've a huge amount of legacy code, and I've to maintain it _as_is_. I'm maintaining a big program. I moved all (program-wide scope)...
9
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang...
5
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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
agi2029
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,...
1
isladogs
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.