Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need to get the value of a field in another form without loading it

Posted on 2006-07-11
4
Medium Priority
?
211 Views
Last Modified: 2010-08-05
Hi.

I have a situation where a checkbox (say chkField) is set in form1.  This passes control to form2, which goes on to form3.  Forms 1 and 2 are still displayed under form3 and as the later forms are closed control is returned to the previous one.

Form3 now needs to know the value of the checkbox in form1.  I can simply reference form1.chkField, and this gets the value OK, but it invokes the Load event in form1 and it blats over the top of form3 on the screen.  Similarly if I try saving the checkbox value in form1's Tag property.

I don't want to set a global variable as there are dozens of forms in this program and this only affects two.  It's frowned upon where I'm working anyway.  

I'm sure there's a simple and elegant solution to this, and it's worth 500 points to me if I can get a quick and simple answer...
0
Comment
Question by:johnhyde
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 17080307
Hi johnhyde,

It sounds to me as if you are assigning a new reference to form1 when you instantiate it:

Dim frm1 As New Form1

For example, this is why using Form1.chkField is creating a new instance, not actually getting the instance you already have.

You can either preserve this reference or iterate the forms collection and locate the appropriate member:

Dim frm As Form
For each frm In Forms
    If frm is Form1 Then
        msgbox frm.chkField
        Exit For ' we found it so we don't need to check any more
    End If
Next

Tim Cottee
0
 

Author Comment

by:johnhyde
ID: 17080358
Many thanks for the swift answer, Tim.

I'm not doing any sort of new Dim statement for the form - I need to pass the checkbox value to a stored procedure and I just use the statement

pParameterValue:=form1.chkField

I'll try iterating through the forms, though, in case that makes a difference.  I'll get back to you shortly on that one.
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 2000 total points
ID: 17080365
johnhyde,

I don't expect that you are doing a new one, the point is that if you do so the first time you instantiate the form, you have to use this reference at all future points. VB will otherwise try to be clever and realise that form1 is the name of an object in the project and create a new instance of form1 for you. Using the forms collection means that you can get at that instantiated object even if your original variable is out of scope.

Tim
0
 

Author Comment

by:johnhyde
ID: 17080438
Gotcha.

And you're quite right, finding the right member in the forms collection works fine (although I had to change it to say If frm.name = "form1" for some reason).

Many thanks for the excellent answer and clear explanation, Tim - getting this sorted so quickly is a great help.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question