473,657 Members | 2,507 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

kcdoell
230 New Member
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 1606
ADezii
8,834 Recognized Expert Expert
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,568 Recognized Expert Moderator MVP
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 New Member
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,568 Recognized Expert Moderator MVP
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
3216
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 lost when they move to a new record. This seems to be the case when there are multiple users. When there is a single user using it, we don't seem to have that problem. It seems that we had this problem when we first converted from an MDB back end...
5
24188
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 some problems with our database crashing. We would therefore like another way to have access to basic student data and thought we automatically save the results of this query when we close Access. Any suggestions on how we could do this would be...
2
6550
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 tblClearance. I was thinking of placing the code on the form's BeforeUpdate event so that it will fire whether the user closes the form or attempts to create another record.
8
1736
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 tblMonthly ON tblTransactions.PshpID = tblMonthly.PshpID " _ & "WHERE tblTransactions.TransDate BETWEEN #12/31/03# AND #05/31/04# " _
2
4392
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 produce the results I want in a separate form (filter by form). No problem, except I want to save the sql to a query, not a form. When I debug.print the various sql, I get something like this example: (( LIKE "cam*")) which obviously is not enough...
15
5640
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. Simply, I'm including one calcualtion from a separate table/query. It sums the total units sold to date by ProductID number and is used in other select queries to perform various calculations. Perhaps there is an advantage in working with a maximum...
4
3518
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 dropdown list from which he can select, because the parameters are rather long... Does anyone know how to make that dropdown list? TIA
15
4392
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 of students and columns of activities and the data are the students' scores in each activity. No problem, almost. The problem is that there are five classes at the moment and will be more classes (or courses) in future semesters. I don't want...
18
7237
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 investigating regarding the error which I will explain shortly, and thus far it has all pertained to WHERE clauses relating to forms causing errors when transferred over to VBA. My issue is a wee bit different and I will explain the situation...
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8825
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7324
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.