I have been struggling with understanding paramater queries for awhile now. I am currently working on the following code. There are three paramters for the query. The first two are pulled from an open form and the third is supplied based on the value of me.questionID. I have this code running on Form_Current.
What happens is that as soon as the form is opening (I can't even see it yet on my screen), I am prompted to enter all three variables. What I want to happen is that the variables are set by the code.
I can set up the code with individual queries and get it to work, but that seems like a lot of repetitive code. I would really like to get to the point where I understand parameter queries and how to use visual basic to pass the information to the query. Based on the posts in this forum, I think I am at least headed in the right direction with my code. Do you see any improvements I can make that might get this working properly?
Thank you!
Code:
Dim dbs As dao.Database
Dim rst As dao.Recordset
Dim qdf As dao.QueryDef
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs!qrysbfrmResponse
qdf.Parameters![ScreenDateParm] = [Forms]![frmEnterNS]![ScreenDateID]
qdf.Parameters![ClientIDParm] = [Forms]![frmEnterNS]![ClientID]
Select Case Me.QuestionID
Case 31, 6
Me.sbfrmResponse.Visible = True
qdf.Parameters![Response] = 63
Set rst = qdf.OpenRecordset
Case Else
Me.sbfrmResponse.Visible = False
End Select
What happens is that as soon as the form is opening (I can't even see it yet on my screen), I am prompted to enter all three variables. What I want to happen is that the variables are set by the code.
I can set up the code with individual queries and get it to work, but that seems like a lot of repetitive code. I would really like to get to the point where I understand parameter queries and how to use visual basic to pass the information to the query. Based on the posts in this forum, I think I am at least headed in the right direction with my code. Do you see any improvements I can make that might get this working properly?
Thank you!