Setting Global variables (1 Viewer)

Meltdown

Registered User.
Local time
Today, 00:44
Joined
Feb 25, 2002
Messages
472
Hi all,

How do i create a variable that will be visible to all Forms after it is created?

At the top of my module I have:
Code:
  'globalvarable to hold the line-item count for each section on the order form
    Global varHardware, varSupport, varEng As Integer

My function is:

Code:
Public Sub GetLineItemCount(OrderID As Integer)
On Error GoTo Error_Handler

 
        'count the number of line-items in each section of the form
        varHardware = DCount("[OrderID]", "OrderDetails", "[ProductID] IS NOT NULL AND [OrderID]=" & OrderID)
          varSupport = DCount("[OrderID]", "OrderDetails2", "[OrderID]=" & OrderID & " AND [ServiceTypeID]=1")
             varEng = DCount("[OrderID]", "OrderDetails2", "[OrderID]=" & OrderID & " AND [ServiceTypeID]=2")


Exit_Handler_Click:
    Exit Sub

Error_Handler:
    MsgBox Err.Description
    Resume Exit_Handler_Click
End Sub

When an Order form loads I call my function with:
Code:
' get the line-item count for each section - Module 1
Call GetLineItemCount(Me.OpenArgs)

That sets the values and the Order form can see the values, however when I open another Form from my Order Form , the variable values come back empty or NULL.

What am I doing wrong?

Thanks
melt
 

DCrake

Remembered
Local time
Today, 00:44
Joined
Jun 8, 2005
Messages
8,632
Couple of things

The global variables need defining outside of the form in a standard module
Each variable needs defining seperately, not implicitly, as you have done.
Also it is better to use Public as opposed to Global even though both work


Code:
MdlMain:

Public Var1 As [I]VarType[/I]
Public Var2 As [I]VarType[/I]
Public Var3 As [I]VarType[/I]


When opening a form then refer to them a such

Me.TextBox = Var1


Have you tried stepping through your Sub to see the variables being populated?
 

Meltdown

Registered User.
Local time
Today, 00:44
Joined
Feb 25, 2002
Messages
472
Thanks DCrake, got it sorted now.:)
 

Users who are viewing this thread

Top Bottom