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 -
Public ShippingType as Integer
Then i set a value to it with buttons on a popup form like this -
Private Sub customer_Click()
-
DoCmd.OpenForm "frmshipping", acNormal, , , acFormAdd
-
ShippingType = 1
-
DoCmd.Close acForm, "frmshiptype"
-
End Sub
-
-
Private Sub transfer_Click()
-
DoCmd.OpenForm "frmshipping", acNormal, , , acFormAdd
-
ShippingType = 2
-
DoCmd.Close acForm, "frmshiptype"
-
End Sub
-
-
Private Sub vendor_Click()
-
DoCmd.OpenForm "frmshipping", acNormal, , , acFormAdd
-
ShippingType = 3
-
DoCmd.Close acForm, "frmshiptype"
-
End Sub
-
Then on the form "frmshipping" i placed in the OnCurrent Event -
If ShippingType = 1 then
-
blah blah blah
-
end if
-
-
if ShippingType = 2 then
-
blah blah blah
-
end if
-
-
if ShippingType = 3 then
-
blah blah blah
-
end if
Then when it wasnt working properly i added this before the if/thens
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 - ShippingType = 1
-
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
2 1910
Nevermind, i cuaght it when reading my post.
I changed - Private Sub customer_Click()
-
DoCmd.OpenForm "frmshipping", acNormal, , , acFormAdd
-
ShippingType = 1
-
DoCmd.Close acForm, "frmshiptype"
-
End Sub
-
to this - Private Sub customer_Click()
-
ShippingType = 1
-
DoCmd.OpenForm "frmshipping", acNormal, , , acFormAdd
-
DoCmd.Close acForm, "frmshiptype"
-
End Sub
I cant beleive I missed that.....
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. - Sub OpenToCallahan()
-
DoCmd.OpenForm "Employees", acNormal, , , acReadOnly, _
-
, "Callahan"
-
End Sub
-
-
Sub Form_Open(Cancel As Integer)
-
Dim strEmployeeName As String
-
' If OpenArgs property contains employee name, find
-
' corresponding employee record and display it on form. For
-
' example,if the OpenArgs property contains "Callahan",
-
' move to first "Callahan" record.
-
strEmployeeName = Forms!Employees.OpenArgs
-
If Len(strEmployeeName) > 0 Then
-
DoCmd.GoToControl "LastName"
-
DoCmd.FindRecord strEmployeeName, , True, , True, , True
-
End If
-
End Sub
-Stewart
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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,...
|
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?
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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$) {
}
...
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
| |