I have approximatley 10 select queries set up which are run on a monthly basis. The common factor between these queries is that they all use the same parameters (start date and end date)
What i would like to do is run all 10 of these queries and only have to enter the parameters once. I have looked into a few ways of doing this and firstly settled on using two text boxes on a form which i then referenced in the query criteria. This however isn't very user friendly because if i wanted to run one of the queries on an ad hoc basis i'd be given something similar to [Forms]![frmPJ_DQ]![txtStartDate] when requesting for the parameters to be input.
I then decided on the below solution but still no luck as i cannot display the results of the queries on screen. It would be fine if they were action queries but as they are all select queries i have a slight problem!
Private Sub btnRunDQ_Click()
Dim cmd As ADODB.Command
Dim prm1 As ADODB.Parameter
Dim prm2 As ADODB.Parameter
Dim dtStartDate As Date
Dim dtEndDate As Date
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdStoredProc
dtStartDate = txtStartDate
dtEndDate = txtEndDate
Set prm1 = cmd.CreateParameter("Enter Start Date", adDate, adParamInput, , dtStartDate)
Set prm2 = cmd.CreateParameter("Enter Day After End Date", adDate, adParamInput, , dtEndDate)
cmd.Parameters.Append prm1
cmd.Parameters.Append prm2
cmd.CommandText = "PJDQ_Dummy"
cmd.Execute
cmd.CommandText = "PJDQ_NotKnown"
cmd.Execute
cmd.CommandText = "PJDQ_NowLeft"
cmd.Execute
cmd.CommandText = "PJDQ_NotWithinEpDates"
cmd.Execute
End Sub
Can anyone be of help here please?
Thanks,
Paul
What i would like to do is run all 10 of these queries and only have to enter the parameters once. I have looked into a few ways of doing this and firstly settled on using two text boxes on a form which i then referenced in the query criteria. This however isn't very user friendly because if i wanted to run one of the queries on an ad hoc basis i'd be given something similar to [Forms]![frmPJ_DQ]![txtStartDate] when requesting for the parameters to be input.
I then decided on the below solution but still no luck as i cannot display the results of the queries on screen. It would be fine if they were action queries but as they are all select queries i have a slight problem!
Private Sub btnRunDQ_Click()
Dim cmd As ADODB.Command
Dim prm1 As ADODB.Parameter
Dim prm2 As ADODB.Parameter
Dim dtStartDate As Date
Dim dtEndDate As Date
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdStoredProc
dtStartDate = txtStartDate
dtEndDate = txtEndDate
Set prm1 = cmd.CreateParameter("Enter Start Date", adDate, adParamInput, , dtStartDate)
Set prm2 = cmd.CreateParameter("Enter Day After End Date", adDate, adParamInput, , dtEndDate)
cmd.Parameters.Append prm1
cmd.Parameters.Append prm2
cmd.CommandText = "PJDQ_Dummy"
cmd.Execute
cmd.CommandText = "PJDQ_NotKnown"
cmd.Execute
cmd.CommandText = "PJDQ_NowLeft"
cmd.Execute
cmd.CommandText = "PJDQ_NotWithinEpDates"
cmd.Execute
End Sub
Can anyone be of help here please?
Thanks,
Paul