one query and many forms

L

LGarcia

Hi all,
I have 1 query and 10 forms. The query is used as a look up for a field
(StudentID) on all 10 forms.
Per request, I added an unbound combo box on all 10 forms (cbo151). I'd like
to use the value in this combo box as a parameter for a field in the query.
Is there a way I can grab the value in the combo box from the current open
form and pass it to the query?
I used Forms!myForm1!cbo151 as the parameter but it needs to change for the
next form. I'd hate to create 9 more queries.
Is there an easier way?
Thanks,
LGarcia
 
G

Guest

You can use a function to pass the value to the query
----------------------
Create a function within a module

Function GetStudentId() As Long
GetStudentId = StudentIdParam
End Function
--------------------------
Declare StudentIdParam within the module (not within the function)

Global StudentIdParam As Long
 
L

LGarcia

Thanks! I'll give it a try.


Ofer Cohen said:
You can use a function to pass the value to the query
----------------------
Create a function within a module

Function GetStudentId() As Long
GetStudentId = StudentIdParam
End Function
--------------------------
Declare StudentIdParam within the module (not within the function)

Global StudentIdParam As Long

--------------------------
Before you open the query assign the combo value to StudentIdParam

StudentIdParam = Me.[ComboName]
Docmd.OpenQuery "QueryName"

--------------------------
In the query you can refer to the function

Select * From TableName Where StudentId = GetStudentId()
--------------------------

Note: I declared the student id as long, change the type if you need to.
--
Good Luck
BS"D


LGarcia said:
Hi all,
I have 1 query and 10 forms. The query is used as a look up for a field
(StudentID) on all 10 forms.
Per request, I added an unbound combo box on all 10 forms (cbo151). I'd
like
to use the value in this combo box as a parameter for a field in the
query.
Is there a way I can grab the value in the combo box from the current
open
form and pass it to the query?
I used Forms!myForm1!cbo151 as the parameter but it needs to change for
the
next form. I'd hate to create 9 more queries.
Is there an easier way?
Thanks,
LGarcia
 

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