Hello,
I am trying to write some VBA code so that the user of my database does not have to enter the parameter to the query. I have tried unsuccessfully two attempts to do that. neither one is working. Can someone help?
First way:
Option Compare Database
Private Sub cmdDialysis_Click()
Dim qdf As DAO.QueryDef 'Name of the pre-defined Query
Dim rst As DAO.Recordset
'then we'll open up the query:
Set qdf = CurrentDb.QueryDefs("qryQuestions")
qdf.Parameters("[Please enter Questionnaire ID]") = 8
Set rst = CurrentDb.OpenRecordset("qryQuestions", dbOpenDynaset) //I am getting error at this line, I also tried this without any parameters and as qdf.OpenRecordset and using "qdf.Execute dbFailOnError" instead
End Sub
Second way: In this case, the criteria of QUESN_ID field of the qryQuestions was set to =GetValue().
Option Compare Database
Option Explicit
Public numValue As Integer
Function SetValue(num As Integer)
numValue = num
End Function
Function GetValue()
GetValue = numValue
End Function
Private Sub cmdDialysis_Click()
Dim num As Integer
num = 8
Call SetValue(num)
DoCmd.OpenQuery "qryQuestions", , acReadOnly
End Sub