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…
4 1593
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. - 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.
-
Public varCombo1Value As Variant
-
Public varCombo2Value As Variant
-
Public varCombo2Value As Variant
- Prior to Form1 closing, place the Values of these Combo Boxes into the previously declared Variables, substituting your own Control names.
-
varCombo1Value = Me![cboCombo1]
-
varCombo2Value = Me![cboCombo2]
-
varCombo3Value = Me![cboCombo3]
- 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:
-
Private Sub Form_Open(Cancel As Integer)
-
Dim strSQL As String
-
-
strSQL = "Select * From Employees Where [FirstName] = '" & varCombo1Value & "' And [LastName] = '" & varCombo2Value & "' And [City] = '" & varCombo3Value & "';"
-
-
Me.RecordSource = strSQL
-
End Sub
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.
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): -
Private Sub cmdTarget_Click()
-
'first hide the forecast form (we need the values for TargetAccts' form query)
-
Forms!Forecast.Visible = False
-
'then Open the target accounts form
-
DoCmd.OpenForm ("TargetAccts")
-
End Sub
-
Thanks to both of you!
Keith.
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 :)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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.
...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
| |