G
Guest
I am trying to modify an existing query by using VB. I need to randomly
select an X number of records without having the user change the top values
property of the query each time it is run. I have written the following code
and placed it in a new module of the database. My problem is that when I
close the module, the existing query is not being modified.
Any suggestions?
Public Sub NewQueryDef()
'Create a new query definition that changes the SQL of existing query
Dim dbsCurrent As Database
Dim myqs As QueryDef
Set dbsCurrent = CurrentDb
Set myqs = dbsCurrent.QueryDefs("Random Families")
myqs.SQL = "SELECT Top " & X & " Families.* From Families ORDER BY
Rnd([ID]);"
End Sub
select an X number of records without having the user change the top values
property of the query each time it is run. I have written the following code
and placed it in a new module of the database. My problem is that when I
close the module, the existing query is not being modified.
Any suggestions?
Public Sub NewQueryDef()
'Create a new query definition that changes the SQL of existing query
Dim dbsCurrent As Database
Dim myqs As QueryDef
Set dbsCurrent = CurrentDb
Set myqs = dbsCurrent.QueryDefs("Random Families")
myqs.SQL = "SELECT Top " & X & " Families.* From Families ORDER BY
Rnd([ID]);"
End Sub