Strike_Eagle
Registered User.
- Local time
- Today, 05:01
- Joined
- Oct 20, 2011
- Messages
- 48
Hello again everyone.
I have a series of queries that are used in various forms and reports. Two of my queries are specialistLookupQuery and countOfSpecialistLookupQuery. While I know I can generally get away with one query for this, they are used for many different reasons throughout the database, plus, thats how my boss wants it (not a school project).
The problem:
According to the facility that logs in (stored in a [TempsVar]![varFacility]) my above two queries have different records. One facility might have 180 people, another 250, and each facility changes each day, so nothing static. I need to pull a random 10% of the people for each facility for evaluation.
How do I open the count query and get the number (countOfSpecialistLookupQuery with a CountOfLastName field) stored in its only field and process it in my VBA code? I will also need to store the names generated in the original query (specialistLookupQuery) in an array and use the random generator to pick ten percent.
I can great a random object in VBA no problem. I cna create an array no problem. I can use the random numbers generated (loops and all that jazz). I just can't figure out how to get that varFacility variable into my query from VBA. Here's what I have so far:
I have a series of queries that are used in various forms and reports. Two of my queries are specialistLookupQuery and countOfSpecialistLookupQuery. While I know I can generally get away with one query for this, they are used for many different reasons throughout the database, plus, thats how my boss wants it (not a school project).
The problem:
According to the facility that logs in (stored in a [TempsVar]![varFacility]) my above two queries have different records. One facility might have 180 people, another 250, and each facility changes each day, so nothing static. I need to pull a random 10% of the people for each facility for evaluation.
How do I open the count query and get the number (countOfSpecialistLookupQuery with a CountOfLastName field) stored in its only field and process it in my VBA code? I will also need to store the names generated in the original query (specialistLookupQuery) in an array and use the random generator to pick ten percent.
I can great a random object in VBA no problem. I cna create an array no problem. I can use the random numbers generated (loops and all that jazz). I just can't figure out how to get that varFacility variable into my query from VBA. Here's what I have so far:
Code:
Const constantQueryName As String = "countOfSpecialistLookupQuery"
Dim database As DAO.database
Dim recordset As DAO.recordset
Dim queryDef As queryDef
Dim parameter As parameter
Dim recordsToUse As Integer
Set database = CurrentDb
Set queryDef = database.QueryDefs(constantQueryName)
Set recordset = queryDef.OpenRecordset()
parameter.Value = varFacility
recordsToUse = recordset![CountOfLastName]
MsgBox "You have " & recordsToUse & " records."
recordset.Close
database.Close