Hi I'm creating an access program that will automatically generate random samples.
Samples are generated by using an SQL query and the resulting query is appended to a table.
The sample generations works fine by setting criteria thru a textbox inside a form. However, I'm thinking if i could also automate the criterias inputed in the sql query.
Old method:
users input paramater and generate samples per branch on at a time...
My plan:
generate all samples for all offices base on pre define samples with just a click of a button.
Ex... if there are 30 branches... and required sample is 5 per branch...the total rows for the resulting table would be 150.
here's what i have in mind, I pasted the code below to the button...however the program doesnt seem to follow the criterias...
Thanks in advance for those who could help me.... or could have any suggestions.
Code:
'three branches with 5 samples each
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSql As String
Dim strTopVal As String
Dim strcrit As String
Dim count As Integer
Set db = CurrentDb
'strTopVal = InputBox("Enter number of samples:")
count = 0
strSql = "SELECT TOP 5 BRANCH, CR, SIN, MEDIUM, ST, RECPTDATE, LSTACT, RESDTE, TYPE" & _
" FROM BC " & strcrit & " " & _
" ORDER BY RandomNumber([SIN]);"
Do Until count = 2
DoCmd.SetWarnings False
db.QueryDefs.Delete "MyTopQuery"
if count=0 then strcrit=" branch='branchA'"
if count=1 then strcrit=" branch='branchB'"
if count=2 then strcrit=" branch='branchC'"
Set qdf = db.CreateQueryDef("MyTopQuery", strSql)
DoCmd.OpenQuery "Query7"
DoCmd.SetWarnings True
count = count + 1
Loop
End Sub
'query7 appends the resulting samples (5 per branch) to the main table per each loop
Samples are generated by using an SQL query and the resulting query is appended to a table.
The sample generations works fine by setting criteria thru a textbox inside a form. However, I'm thinking if i could also automate the criterias inputed in the sql query.
Old method:
users input paramater and generate samples per branch on at a time...
My plan:
generate all samples for all offices base on pre define samples with just a click of a button.
Ex... if there are 30 branches... and required sample is 5 per branch...the total rows for the resulting table would be 150.
here's what i have in mind, I pasted the code below to the button...however the program doesnt seem to follow the criterias...
Thanks in advance for those who could help me.... or could have any suggestions.
Code:
'three branches with 5 samples each
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSql As String
Dim strTopVal As String
Dim strcrit As String
Dim count As Integer
Set db = CurrentDb
'strTopVal = InputBox("Enter number of samples:")
count = 0
strSql = "SELECT TOP 5 BRANCH, CR, SIN, MEDIUM, ST, RECPTDATE, LSTACT, RESDTE, TYPE" & _
" FROM BC " & strcrit & " " & _
" ORDER BY RandomNumber([SIN]);"
Do Until count = 2
DoCmd.SetWarnings False
db.QueryDefs.Delete "MyTopQuery"
if count=0 then strcrit=" branch='branchA'"
if count=1 then strcrit=" branch='branchB'"
if count=2 then strcrit=" branch='branchC'"
Set qdf = db.CreateQueryDef("MyTopQuery", strSql)
DoCmd.OpenQuery "Query7"
DoCmd.SetWarnings True
count = count + 1
Loop
End Sub
'query7 appends the resulting samples (5 per branch) to the main table per each loop