I am having this problem with my coding that i have created a form that will have a combo box with two values of intialing a report,,
the thing is when i ever want to do the docmd.openreport
it gives empty report , and i cant see where is the error ???!!!
this is the code if could someone look at it
thanx in Advance
the thing is when i ever want to do the docmd.openreport
it gives empty report , and i cant see where is the error ???!!!
this is the code if could someone look at it
Code:
Private Sub btnPreview_Click()
'Purpose: Filter a report to a date range.
Dim strReport_1 As String
Dim strReport_2 As String
Dim strDateField As String
Dim strWhere As String
Dim lngView As Long
Dim str As String
strReport_1 = "Report_Supply_Log_StaffDeptByDate"
strReport_2 = "Report_SupplyLog_SupplierByDate"
strDateField = "[Supply_Log.Date]"
lngView = acViewPreview
If (Me.Report_type.value = "Supplier Report") Then
If IsDate(Me.txtStartDate) Then
str = "Supplier"
strWhere = "( [Supply_Log.Supply_Type] = " & str & " And " & Format(strDateField, "mm/dd/yyyy") & " >= " & Format(Me.txtStartDate, "mm/dd/yyyy") & " )"
End If
If IsDate(Me.txtEndDate) Then
If strWhere <> vbNullString Then
strWhere = strWhere & " AND "
End If
strWhere = strWhere & "( [Supply_Log.Supply_Type] = " & str & " And " & Format(strDateField, "mm/dd/yyyy") & " < " & Format(Me.txtEndDate + 1, "mm/dd/yyyy") & ")"
End If
'Close the report if already open
If CurrentProject.AllReports(strReport_2).IsLoaded Then
DoCmd.Close acReport, strReport_2
End If
'Open the report.
Debug.Print strWhere
DoCmd.OpenReport strReport_2, lngView, , strWhere
ElseIf (Me.Report_type = "Staff/Dept Report") Then
If IsDate(Me.txtStartDate) Then
strWhere = "( Supply_Log.Supply_Type = Staff/Dept And " & strDateField & " >= " & Format(Me.txtStartDate, strcJetDate) & " )"
End If
If IsDate(Me.txtEndDate) Then
If strWhere <> vbNullString Then
strWhere = strWhere & " AND "
End If
strWhere = strWhere & "( Supply_Log.Supply_Type = Staff/Dept And " & strDateField & " < " & Format(Me.txtEndDate + 1, strcJetDate) & ")"
End If
'Close the report if already open
If CurrentProject.AllReports(strReport_2).IsLoaded Then
DoCmd.Close acReport, strReport_2
End If
Debug.Print strWhere
DoCmd.OpenReport strReport_2, lngView, , strWhere
End If
End Sub