one query from two different forms (different Parameters)

L

learning_codes

Hi,

I have two same queries that have different parameters but two
forms . The two different forms have the box like "txtLastName" that
goes to the queries to open the result. I want to combine two
queries into one queries when I select either two forms that can open
one query. When I select a button on either two forms and run one
query with a crietria "txtLastName" from two different forms.

I'm learning and would like to learn from you if you provide me the
step by step.

Your help would be much appreciated.
Thanks.
 
J

Jeanette Cunningham

Hi,
Put a combo on the form where user can select the LastName they want.
Use the wizard, select the combo tool, choose the option about looking up a
list from a table.
Choose to add the ID and Lastname fields.
Make the ID hidden and sort the LastName field ascending.
In the after update event for the combo put some code that passes the ID
from the combo to the query.

Post back with details of what you want to happen after the user chooses the
LastName, and we can help with the code.

Jeanette Cunningham
 
L

learning_codes

Hi,
Put a combo on the form where user can select the LastName they want.
Use the wizard, select the combo tool, choose the option about looking up a
list from a table.
Choose to add the ID and Lastname fields.
Make the ID hidden and sort the LastName field ascending.
In the after update event for the combo put some code that passes the ID
from the combo to the query.

Post back with details of what you want to happen after the user chooses the
LastName, and we can help with the code.

Jeanette Cunningham









- Show quoted text -

I'm still learning how to make two different forms to one query.
Right now, I have two queries.

The forms are:

[Forms].[frm_Sport].txtLastName (connect to the query: qry_Sport
[Forms].[frm_Location].txtLastName (connect to the query:
qry_Location)

The two queries are the same query. I want to combine qry_Sport and
qry_Location into one query. Both two forms can run on the query with
two different parameters when I want to use the form (sport) and than
later use the form (location) to run the same query. The query can
check which forms I use the forms: Sport or Location. Is that
possible?

Is that help you to provide some information for me?

Thanks
 
J

Jeanette Cunningham

I'm not sure I understand what you are doing.

If you want to pass a parameter to a query, here is a way I do it in code.

Dim strSQL as String
strSQL = "SELECT [TheTableName].[Field1], [TheTableName].[Field2] " _
& "FROM [TheTableName] " _
& "WHERE [TheTableName].LastName = """ & Me.txtLastName & """"
& "ORDER BY [ThetableName].[Field1]"
Debug.Print strSQL

You use the above as the query, it replaces both the saved queries you have.
Post back if you wanted to do something different.

Jeanette Cunningham


Hi,
Put a combo on the form where user can select the LastName they want.
Use the wizard, select the combo tool, choose the option about looking up
a
list from a table.
Choose to add the ID and Lastname fields.
Make the ID hidden and sort the LastName field ascending.
In the after update event for the combo put some code that passes the ID
from the combo to the query.

Post back with details of what you want to happen after the user chooses
the
LastName, and we can help with the code.

Jeanette Cunningham









- Show quoted text -

I'm still learning how to make two different forms to one query.
Right now, I have two queries.

The forms are:

[Forms].[frm_Sport].txtLastName (connect to the query: qry_Sport
[Forms].[frm_Location].txtLastName (connect to the query:
qry_Location)

The two queries are the same query. I want to combine qry_Sport and
qry_Location into one query. Both two forms can run on the query with
two different parameters when I want to use the form (sport) and than
later use the form (location) to run the same query. The query can
check which forms I use the forms: Sport or Location. Is that
possible?

Is that help you to provide some information for me?

Thanks
 
L

learning_codes

I'm not sure I understand what you are doing.

If you want to pass a parameter to a query, here is a way I do it in code.

Dim strSQL as String
strSQL = "SELECT [TheTableName].[Field1], [TheTableName].[Field2] " _
    & "FROM [TheTableName] " _
    & "WHERE [TheTableName].LastName = """ & Me.txtLastName & """"
    & "ORDER BY [ThetableName].[Field1]"
Debug.Print strSQL

You use the above as the query, it replaces both the saved queries you have.
Post back if you wanted to do something different.

Jeanette Cunningham


Hi,
Put a combo on the form where user can select the LastName they want.
Use the wizard, select the combo tool, choose the option about looking up
a
list from a table.
Choose to add the ID and Lastname fields.
Make the ID hidden and sort the LastName field ascending.
In the after update event for the combo put some code that passes the ID
from the combo to the query.
Post back with details of what you want to happen after the user chooses
the
LastName, and we can help with the code.
Jeanette Cunningham
- Show quoted text -

I'm still learning how to make two different forms to one query.
Right now, I have two queries.

The forms are:

[Forms].[frm_Sport].txtLastName   (connect to the query:  qry_Sport
[Forms].[frm_Location].txtLastName  (connect to the query:
qry_Location)

The two queries are the same query.  I want to combine qry_Sport and
qry_Location into one query.  Both two forms can run on the query with
two different parameters when I want to use the form (sport) and than
later use the form (location) to run the same query.  The query can
check which forms I use the forms: Sport or Location.   Is that
possible?

Is that help you to provide some information for me?

Thanks- Hide quoted text -

- Show quoted text -

Thank you for very much for example and it will give me more thinking
how to use this. I'm just a learning how to set SQL instead of query.

Will that possible to have 3 queries into one query like strSQL,
strSQL2, strSQL3 to run the same time ?

Thanks.
 
J

Jeanette Cunningham

You can have 3 queries and run them one after the other like this:

Dim strSQL as String
Dim db as DAO.Database

Set db = CurrentDb()

strSQL = "...your 1st query code here ..."
Debug.Print strSQL
db.Execute strSQL, dbFailOnError

strSQL = "...your 2nd query code here ..."
Debug.Print strSQL
db.Execute strSQL, dbFailOnError

strSQL = "...your 3rd query code here ..."
Debug.Print strSQL
db.Execute strSQL, dbFailOnError

In the exit part of your sub, make sure you set db to Nothing

SubExit:
Set db = Nothing
Exit Sub

SubErr:
Msgbox err.Number & " " & err.Description
Resume SubExit
End Sub

Jeanette Cunningham

I'm not sure I understand what you are doing.

If you want to pass a parameter to a query, here is a way I do it in code.

Dim strSQL as String
strSQL = "SELECT [TheTableName].[Field1], [TheTableName].[Field2] " _
& "FROM [TheTableName] " _
& "WHERE [TheTableName].LastName = """ & Me.txtLastName & """"
& "ORDER BY [ThetableName].[Field1]"
Debug.Print strSQL

You use the above as the query, it replaces both the saved queries you
have.
Post back if you wanted to do something different.

Jeanette Cunningham


Hi,
Put a combo on the form where user can select the LastName they want.
Use the wizard, select the combo tool, choose the option about looking
up
a
list from a table.
Choose to add the ID and Lastname fields.
Make the ID hidden and sort the LastName field ascending.
In the after update event for the combo put some code that passes the ID
from the combo to the query.
Post back with details of what you want to happen after the user chooses
the
LastName, and we can help with the code.
Jeanette Cunningham
- Show quoted text -

I'm still learning how to make two different forms to one query.
Right now, I have two queries.

The forms are:

[Forms].[frm_Sport].txtLastName (connect to the query: qry_Sport
[Forms].[frm_Location].txtLastName (connect to the query:
qry_Location)

The two queries are the same query. I want to combine qry_Sport and
qry_Location into one query. Both two forms can run on the query with
two different parameters when I want to use the form (sport) and than
later use the form (location) to run the same query. The query can
check which forms I use the forms: Sport or Location. Is that
possible?

Is that help you to provide some information for me?

Thanks- Hide quoted text -

- Show quoted text -

Thank you for very much for example and it will give me more thinking
how to use this. I'm just a learning how to set SQL instead of query.

Will that possible to have 3 queries into one query like strSQL,
strSQL2, strSQL3 to run the same time ?

Thanks.
 
J

John W. Vinson

The two queries are the same query. I want to combine qry_Sport and
qry_Location into one query. Both two forms can run on the query with
two different parameters when I want to use the form (sport) and than
later use the form (location) to run the same query. The query can
check which forms I use the forms: Sport or Location. Is that
possible?

Are these *ACTION* queries (queries that do something to data, such as an
append query or an update query)? or are they Select queries? It's rarely
necessary or appropriate to "run" (open) a query datasheet; normally users
should view data on a Form using the query as its recordsource. Could you step
back a bit and tell us *why* you're running these queries? What are you trying
to accomplish?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top