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

Global Variables (setting and using)

Ok, the first thing i found out is that i should be using 'Public' instead of 'Global", so i did that. Here is what i tried to do (yes i have read as much as i could before i posted...... i promise). I set my variables in a module (not a class module) like this
Expand|Select|Wrap|Line Numbers
  1. Public ShippingType as Integer
Then i set a value to it with buttons on a popup form like this
Expand|Select|Wrap|Line Numbers
  1. Private Sub customer_Click()
  2. DoCmd.OpenForm "frmshipping", acNormal, , , acFormAdd
  3. ShippingType = 1
  4. DoCmd.Close acForm, "frmshiptype"
  5. End Sub
  6.  
  7. Private Sub transfer_Click()
  8. DoCmd.OpenForm "frmshipping", acNormal, , , acFormAdd
  9. ShippingType = 2
  10. DoCmd.Close acForm, "frmshiptype"
  11. End Sub
  12.  
  13. Private Sub vendor_Click()
  14. DoCmd.OpenForm "frmshipping", acNormal, , , acFormAdd
  15. ShippingType = 3
  16. DoCmd.Close acForm, "frmshiptype"
  17. End Sub
  18.  
Then on the form "frmshipping" i placed in the OnCurrent Event
Expand|Select|Wrap|Line Numbers
  1. If ShippingType = 1 then
  2. blah blah blah
  3. end if
  4.  
  5. if ShippingType = 2 then 
  6. blah blah blah
  7. end if
  8.  
  9. if ShippingType = 3 then
  10. blah blah blah
  11. end if
Then when it wasnt working properly i added this before the if/thens
Expand|Select|Wrap|Line Numbers
  1. msgbox (ShippingType)
Then ( i will say it this way on purpose) when i open the form the second time using Transfer (ShippingType should be equal to 2), after opening it the first time with Customer (ShippingType = 1) then i get a 1 in the msgbox. Every time i do it it gives me the value from the press before. Beleive it or not, while trying to cheat i decided to do this
Expand|Select|Wrap|Line Numbers
  1. ShippingType = 1
  2. ShippingType = 1
Just to see if delcaring it twice would work...... Well it didnt. Can someone please give me the tip i need to move on. I thought i had global variables figured out because this method actually worked somewhere else (summing numbers from some queries) but it doesnt seem to work here. Any help is appreciated.

Also, when a global variable is used.... is it the same for all users, or are different users able to set different values to it at the same time.

KStevens
Mar 12 '09 #1
2 1910
Nevermind, i cuaght it when reading my post.

I changed
Expand|Select|Wrap|Line Numbers
  1. Private Sub customer_Click() 
  2. DoCmd.OpenForm "frmshipping", acNormal, , , acFormAdd 
  3. ShippingType = 1 
  4. DoCmd.Close acForm, "frmshiptype" 
  5. End Sub 
  6.  
to this
Expand|Select|Wrap|Line Numbers
  1. Private Sub customer_Click() 
  2. ShippingType = 1
  3. DoCmd.OpenForm "frmshipping", acNormal, , , acFormAdd 
  4. DoCmd.Close acForm, "frmshiptype" 
  5. End Sub 
I cant beleive I missed that.....
Mar 12 '09 #2
Stewart Ross
2,545 Expert Mod 2GB
Hi. Well done for catching the error in the sequence of opening the form before you had set the variable concerned.

Something you may consider in the future - as it would do away with the need to use a global variable to pass a value to a form - is to use the OpenArgs string parameter of the OpenForm method to pass the value instead. This can be tested in the form's On Open event to see what its value is, and do whatever is necessary for the form accordingly. The extract from MS Help below for the OpenArgs method (the one that retrieves the value passed) clarifies how it's done:

Example
The following example uses the OpenArgs property to open the Employees form to a specific employee record and demonstrates how the OpenForm method sets the OpenArgs property. You can run this procedure as appropriate— for example, when the AfterUpdate event occurs for a custom dialog box used to enter new information about an employee.

Expand|Select|Wrap|Line Numbers
  1. Sub OpenToCallahan()
  2.     DoCmd.OpenForm "Employees", acNormal, , , acReadOnly, _
  3.      , "Callahan"
  4. End Sub
  5.  
  6. Sub Form_Open(Cancel As Integer)
  7.     Dim strEmployeeName As String
  8.     ' If OpenArgs property contains employee name, find
  9.     ' corresponding employee record and display it on form. For
  10.     ' example,if the OpenArgs property contains "Callahan",
  11.     ' move to first "Callahan" record.
  12.     strEmployeeName = Forms!Employees.OpenArgs
  13.     If Len(strEmployeeName) > 0 Then
  14.         DoCmd.GoToControl "LastName"
  15.         DoCmd.FindRecord strEmployeeName, , True, , True, , True
  16.     End If
  17. End Sub
-Stewart
Mar 12 '09 #3

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

Similar topics

6
by: Bob Darlington | last post by:
I have an Access XP app running over TS with Windows 2000 Server. There are 5 sites (each with 3 or 4 users) accessing the data file, and each has its own front end mde on the server. The mde's...
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...
10
by: ankisharma | last post by:
Hi all At many places I have seen that programmers pass global variables to functions in c. I am not able to figure out why they do so. need some clues on this. somewhere i heard that this...
12
by: jyu.james | last post by:
I'm trying to detect reads of uninitialized global variables (that are declared in one file, and used in another as an extern). I know that ANSI C initializes all global variables to 0, however,...
6
by: Andrea Williams | last post by:
Where is the best place to put global variables. In traditional ASP I used to put all of them into an include file and include it in every page. Will the Global.aspx.cs do that same thing? ...
4
by: kuhrty | last post by:
I am using a window form and trying to get a dataset used in the form globally but I am having an issue setting the property and setting it locally to the class. When I try to call the dataset...
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...
23
by: David Colliver | last post by:
Hi, using c#, 1.1 I know that we are not supposed to use global variables etc. in c# I am having a problem, but not sure how to resolve. I did have another post here, but may have over...
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...
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...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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...

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.