When attempting to pass date parameters through a form into VBA code, the query contains no records. however, if the values are placed in the query, values are returned, for instance, plugging in
instead of the
I would appreciate any guidance.
The following values are being passed through a screen during an event procedure into Access VBA code:
The code that calls this routine is as follows:
Code:
Between #01/1/2010# And #3/3/2010#
Code:
Between [Forms]![F_PR_Status]![txb_Start_Date] And [Forms]![F_PR_Status]![txb_End_Date])
The following values are being passed through a screen during an event procedure into Access VBA code:
Code:
[Forms]![F_PR_Status]![txb_Start_Date] [Forms]![F_PR_Status]![txb_End_Date]
The code that calls this routine is as follows:
Code:
Option Compare Database
Dim rst As DAO.Recordset
Dim rstTemp As Recordset
Dim rstSummary As Recordset
Dim rstWorkflowLength As Recordset
Dim i As Long
Dim dbs As DAO.Database
Dim strSQL As String
Dim strFirstRec As String
Private Sub Create_Report_Click()
On Error GoTo Err_Hndlr
Call Q_PR_date
Create_Report_Click_Exit:
Exit Sub
Err_Hndlr:
MsgBox "[" & Err.Number & "]: " & Err.Description, vbInformation, "Create_Report_Click_Exit()"
End Sub
Private Sub Q_PR_date()
On Error GoTo Err_Hndlr
'**********************************************
Dim dbs As Database
Dim strSQL As String
Dim strQueryName As String
Dim qryDef As QueryDef
Debug.Print Forms!F_PR_Status!txb_Start_Date; " "; Forms!F_PR_Status!txb_End_Date
If (Eval("[Forms]![F_PR_Status]![txb_Start_Date] Is Null")) Then
MsgBox "Please select a Starting Date ", vbInformation, "Required Date"
StartingBoardDate.SetFocus
Exit Sub
End If
If (Eval("[Forms]![F_PR_Status]![txb_End_Date] Is Null")) Then
MsgBox "Please select an Ending Date ", vbInformation, "Required Date"
EndingBoardDate.SetFocus
Exit Sub
End If
'set variable values
Set dbs = CurrentDb
strQueryName = "sql_PR_date"
'Delete old query first - we want fresh data!
dbs.QueryDefs.Delete strQueryName
'Notice below how we inserted the variable as a parameter value - Visual Basic will evaluate strMonth and insert the value for us.
strSQL = "SELECT T_PRApprovalHistory.PR_ID, " & _
"T_PRApprovalHistory.PR_Date, " & _
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
"T_PRApprovalHistory.Workflow_Step_Name, " & _
"T_PRApprovalHistory.Workflow_Step_Date, " & _
"Count(T_PRApprovalHistory.Workflow_Step_Date) AS CountOfWorkflow_Step_Date " & _
"FROM T_PRApprovalHistory " & _
"INNER JOIN tblWorkflowApprovalStep ON " & _
"T_PRApprovalHistory.Workflow_Step_Name = tblWorkflowApprovalStep.Workflow_Step_Name " & _
"GROUP BY T_PRApprovalHistory.PR_ID, " & _
"T_PRApprovalHistory.PR_Date, " & _
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
"T_PRApprovalHistory.Workflow_Step_Name, " & _
"T_PRApprovalHistory.Workflow_Step_Date " & _
"HAVING (((T_PRApprovalHistory.PR_Date) " & _
"Between [Forms]![F_PR_Status]![txb_Start_Date] And [Forms]![F_PR_Status]![txb_End_Date])) " & _
"ORDER BY T_PRApprovalHistory.PR_ID, " & _
"tblWorkflowApprovalStep.Workflow_Step_Order, " & _
"T_PRApprovalHistory.Workflow_Step_Date;"
'Create query definition
Set qryDef = dbs.CreateQueryDef(strQueryName, strSQL)
Q_PR_date_Exit:
Exit Sub
Err_Hndlr:
MsgBox "[" & Err.Number & "]: " & Err.Description, vbInformation, "Q_PR_date()"
End Sub
Comment