473,511 Members | 15,156 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Refer to another form's global variable?

1,287 Recognized Expert Top Contributor
Question: Can I set a form's variable from another form?

Details of my problem:

In my Form1, I have
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. 'whether each tab has been updated, so they aren't recalculated unneccesarily
  5. Dim tab0 As Boolean
  6. Dim tab1 As Boolean
  7. Dim tab2 As Boolean
On a subform on a tab control on Form1, I have a button that opens Form2. When it's click, I also want to set the tab1 variable to False, so that when Form2 is done and calls my Update function on Form1, it will know to update the recordsource of the subform on the second page of the tab control on Form1.

Is there any way to set tab1 from the code in the subform? I tried stuff like

Expand|Select|Wrap|Line Numbers
  1.     If CurrentProject.AllForms("View Projects Manager").IsLoaded Then
  2.         Forms![View Projects Manager].Form!tab1 = False
  3.     End If
but no luck. I don't see any way to Dim the variable as Public either.
Dec 11 '08 #1
5 17555
nico5038
3,080 Recognized Expert Specialist
Why not use the tab control to "force" a sequence.
When you hide the tabs (see the properties) and add [Next] and [Previous] buttons you can control the sequence the user has to enter the data like the Access wizards.

Getting the idea ?

Nic;o)
Dec 11 '08 #2
FishVal
2,653 Recognized Expert Specialist
I think this stuff might be helpful.

Regards,
Fish
Dec 11 '08 #3
ChipR
1,287 Recognized Expert Top Contributor
Thanks Nico, but I'm not actually using the tabs as a sequence for entering data, they are for viewing data only, and contain continuous subforms.

FishVal, I had considered using textboxes to store the variables so I could reference them from the subform, but I was wondering if it was really necessary. I decided to just make a public function in Form1 to set the variables, and call it from the subform. It accomplishes the goal of setting the variables at least.
Dec 11 '08 #4
FishVal
2,653 Recognized Expert Specialist
ChipR, if I've understood your correctly, code invoked in Form2 should initiate requiry of certain subform in Form1. Decision about what subform has to be required is made according to variables state (I suppose that the variables depend on Form1 state, maybe Form1.tabcontrol state - so I could guess they are actually redundant).

There are at least 3 general approaches:
  • Open Form2 as modal and let code in Form1 make a job as soon as Form2 is closed.
  • Form2 is allowed to make requiry. For that pass a referense to Form object of relevent Form1 subform control to Form2 via property.
  • Form2 is allowed to notify Form1 to make requiry. For that declare event in Form2 module and raise it when needed, get reference to Form2 object as soon as Form2 has been opened and store it in Form1 module as global object variable declared with events as Form_Form2. Form1 will listen to Form2 events.

The last two methods you could find in article I've suggested you.

Regards,
Fish

P.S.
@ChipR
You could conviniently access form global variable via property.
Dec 11 '08 #5
ADezii
8,834 Recognized Expert Expert
@ChipR
Hello ChipR, I'm not sure that this will really help you in your case but Declaring a Variable As Public in a Form's Class Module essentially makes it a Global Property of the Form. Case in point:
  1. Declare a LONG INTEGER in Form1's Code Module:
    Expand|Select|Wrap|Line Numbers
    1. Public lngReallyBigNum As Long
  2. Initialize lngReallyBigNum anywhere within the context of Form1:
    Expand|Select|Wrap|Line Numbers
    1. lngReallyBigNum = 1987234567
  3. You can now retrieve or set the value of lngReallyBigNum from anywhere within your Application via:
    Expand|Select|Wrap|Line Numbers
    1. Debug.Print Forms!Form1.lngReallyBigNum        'retrieve
    2. Forms!Form1.lngReallyBigNum = 987652            'set
Dec 12 '08 #6

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

Similar topics

9
1560
by: Thomas Christensen | last post by:
If anyone can provide an explanation and/or workaround for this bug in IE I would be really grateful. Is this a known bug?: ******CODE******* <html> <script type="text/javascript"> function...
5
8129
by: Bernard Davis | last post by:
Hi, I need to pass the value held in a field in one form and have it appear in another form. I specifically don't want to have to refer to the original form name as it has passed, because I...
5
2437
by: Mrozu | last post by:
Hi I have frm1. On this form button.Click code for this button is: Dim frm2 as New frm2 frm2.show So after click, frm2 form is shown.
6
6306
by: Leszek | last post by:
Hi. I wrote a script: function zmiana(ile){ while(document.getElementById('accomp').childNodes.length>1){ ostatni=document.getElementById('document.dane.accomp').lastChild;...
6
1669
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why doesn't the global variable "divId" always refer to the element with id="divId"?...
12
2341
by: Rob | last post by:
Let's say you open Form1 that contains TabControl1 There are several tabs on TabControl1 Now you open a new Form2 that contains a User Control How can you determine the Selected tab in Form1...
11
1662
by: Web Search Store | last post by:
Hello, I set up a web page with 2 user controls. In classic asp, the first one did all the declarations, and the second one used the values, and could reset it. In ASP.Net so far I can't...
0
7251
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
7367
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
7430
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...
1
7089
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
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5673
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
5072
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
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3217
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.