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

Losing my query parameters when my form closes that are needed for another form.....

kcdoell
230 100+
I have a form (Form1) that displays records based on 3 unbound combo boxes that are also on my form. My record source for this form is a query “ReQryForecast” (which looks at those combo boxes via the criteria setting of that query). If changes are made to one of the combo boxes, the records displayed will change via my simple code in the after update event of my unbound combo box.

This works fine….

Now I have a command button on Form1 that will launch a new form (Form2) and at the same time close Form1. Form2 also has a record source set to a query “QryTarget” with 3 unbound combo boxes that feed off of it. What I am trying to do use the same parameters that were chosen/displayed in Form1 before it closed. My problem is that I am losing the parameters (in the 3 unbound combo boxes), because I already closed Form1.

Is there a way to retain the choices displayed in the combo boxes of Form1 before I close it, so that it can be used for my Form2 query?

Any ideas would be great.

Thanks,

Keith.

P.S. In the past, I would leave Form 1 open and hide it by having Form2 created as a bigger form. This time, I can not do that. So there in lies my problem that I was using a trick to get by………

Stuck…
Apr 22 '08 #1
4 1593
ADezii
8,834 Expert 8TB
I have a form (Form1) that displays records based on 3 unbound combo boxes that are also on my form. My record source for this form is a query “ReQryForecast” (which looks at those combo boxes via the criteria setting of that query). If changes are made to one of the combo boxes, the records displayed will change via my simple code in the after update event of my unbound combo box.

This works fine….

Now I have a command button on Form1 that will launch a new form (Form2) and at the same time close Form1. Form2 also has a record source set to a query “QryTarget” with 3 unbound combo boxes that feed off of it. What I am trying to do use the same parameters that were chosen/displayed in Form1 before it closed. My problem is that I am losing the parameters (in the 3 unbound combo boxes), because I already closed Form1.

Is there a way to retain the choices displayed in the combo boxes of Form1 before I close it, so that it can be used for my Form2 query?

Any ideas would be great.

Thanks,

Keith.

P.S. In the past, I would leave Form 1 open and hide it by having Form2 created as a bigger form. This time, I can not do that. So there in lies my problem that I was using a trick to get by………

Stuck…
There are several Methods that you can use, this is just one of them.
  1. In a Standard Code Module, declare 3 Public Variables to represent the 3 values of the Combo Boxes on Form1. Since I have no idea of what Data Type(s) are involved, I declared them as Variants.
    Expand|Select|Wrap|Line Numbers
    1. Public varCombo1Value As Variant
    2. Public varCombo2Value As Variant
    3. Public varCombo2Value As Variant
  2. Prior to Form1 closing, place the Values of these Combo Boxes into the previously declared Variables, substituting your own Control names.
    Expand|Select|Wrap|Line Numbers
    1. varCombo1Value = Me![cboCombo1]
    2. varCombo2Value = Me![cboCombo2]
    3. varCombo3Value = Me![cboCombo3]
  3. In the Open() Event of Form2, dynamically build the SQL String and assign it to the Record Source of Form2. Assuming all values are Strings, an example would be something similar to:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Open(Cancel As Integer)
    2. Dim strSQL As String
    3.  
    4. strSQL = "Select * From Employees Where [FirstName] = '" & varCombo1Value & "' And [LastName] = '" & varCombo2Value & "'  And [City] = '" & varCombo3Value & "';"
    5.  
    6. Me.RecordSource = strSQL
    7. End Sub
Apr 23 '08 #2
NeoPa
32,556 Expert Mod 16PB
In your calling form, instead of closing after opening the new one, simply hide your(it)self (Me.Visible = False).

That way, you can either open it again later, or pass the name of the calling form to the new form via OpenArgs and let all called forms try to make the calling form visible again just prior to closing itself.

Opening it again later will simply select it. It won't (I believe) rerun the Form_Open() procedure.
Apr 23 '08 #3
kcdoell
230 100+
ADezil:

I liked your method and is what I was thinking about. I knew there must be a method of storing the variables and using them for future reference... Thanks for your insight and knowledge on the subject.

Because I am pressed for time, I did use NeoPa's down and dirty suggestion (visible = true or false.). It seems to be working so far for what I need it to do. In the end, the following code is what I used, inserted in the "On Click" event of my command button (Form1 = Forecast & Form2 = TargetAccts):
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdTarget_Click()
  2. 'first hide the forecast form (we need the values for TargetAccts' form query)
  3.     Forms!Forecast.Visible = False
  4. 'then Open the target accounts form
  5.     DoCmd.OpenForm ("TargetAccts")
  6. End Sub
  7.  
Thanks to both of you!

Keith.
Apr 23 '08 #4
NeoPa
32,556 Expert Mod 16PB
Multiple ideas always seem to leave food for thought anyway Keith.

I use the hiding of active forms as a standard in all my databases anyway, but I also save data in publicly accessible variables when the need arises.

Glad we could help anyway :)
Apr 23 '08 #5

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

Similar topics

32
by: Neil Ginsberg | last post by:
We're using SQL Server 7 with an Access 2000 MDB as a front end with ODBC linked tables. I recently created a new set of tables for the app, and users are complaining that unsaved data is being...
5
by: Carl | last post by:
Please can anyone tell me how I can create a macro to save the results of a query as an excel file? The query is called Student List and I would like to save it to "My Documents". We have had...
2
by: Paul Wagstaff | last post by:
Hi there I have 2 tables: tblAccuracy & tblClearance Users add new records to tblAccuracy using frmRegister. Under specific conditions I need to append the current record from frmRegister into...
8
by: Yisroel Markov | last post by:
I have the following in my code: strSQL = "SELECT tblTransactions.PshpID, tblTransactions.TransDate, " _ & " Sum(tblTransactions.DDAmount) AS SumDDAmount FROM tblTransactions " _ & "INNER JOIN...
2
by: Seth Delaney | last post by:
I have a form with multiple unbound text boxes which serves as a "search form". I can enter my search parameters in the various boxes as needed and click okay. My records are then filtered to...
15
by: Rolan | last post by:
There must be a way to enhance the performance of a query, or find a plausible workaround, but I seem to be hitting a wall. I have tried a few tweaks, however, there has been no improvement. ...
4
by: Theo Jansen | last post by:
Hi, i'm making an application in Access and in the query made, i'd like the user to fill in a parameter when opening the query (in a report). It's much easier for the user if the parameter was a...
15
by: Richard Hollenbeck | last post by:
I tried to ask this question before on the 14th of January but I never got a reply. I'm still struggling with the problem. I'll try to rephrase the question: I have a crosstab query with rows...
18
by: JGrizz | last post by:
Greetings, I first off want to state that I am new to the forum, so if this question ends up in the wrong area, I apologize. This pertains to Access 2003/VBA/SQL issues... I have been doing some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.