Michaelcree
Instructor
Hi I need to be able to search an Access database table for the occurances of an Item Code between two given dates.
I have created a form with three fields and one button on txtItemCode txtItemCodeReportStartDate txtItemCodeReportEndDate
cmdRunItemCodeReport
I want the user to enter a Item Code in the txtItemCode textbox a start and end date and on clicking the button open a report to display all the occurances of that Item code within the date range.
I have managed to get it to work searching with just the ItemCode but am now not sure how to add the date variables in?
This is the code I have so far:
Private Sub cmdRunItemCodeReport_Click()
If TxtItemCode > 0 Then
DoCmd.OpenReport "rptItemCodes", , , ReportResults
TxtItemCode = ""
Else:
MsgBox "Please enter an Item Code"
End If
End Sub
Private Function ReportResults() As String
If Len(TxtItemCode) <> 0 And Not IsNull(TxtItemCode) Then
ReportResults = ReportResults & " (tblReturns.ItemCode LIKE '%" & Trim(TxtItemCode) & "%' "
' ReportResults = ReportResults & " And tblReturns.ReceivedDate LIKE '%" & (DATEDIFF(dd, txtItemCodeReportStartDate, txtItemCodeReportEndDate) & "%' "
ReportResults = ReportResults & ")"
End If
End Function
Many Thanks for anyhelp in advance.
I have created a form with three fields and one button on txtItemCode txtItemCodeReportStartDate txtItemCodeReportEndDate
cmdRunItemCodeReport
I want the user to enter a Item Code in the txtItemCode textbox a start and end date and on clicking the button open a report to display all the occurances of that Item code within the date range.
I have managed to get it to work searching with just the ItemCode but am now not sure how to add the date variables in?
This is the code I have so far:
Private Sub cmdRunItemCodeReport_Click()
If TxtItemCode > 0 Then
DoCmd.OpenReport "rptItemCodes", , , ReportResults
TxtItemCode = ""
Else:
MsgBox "Please enter an Item Code"
End If
End Sub
Private Function ReportResults() As String
If Len(TxtItemCode) <> 0 And Not IsNull(TxtItemCode) Then
ReportResults = ReportResults & " (tblReturns.ItemCode LIKE '%" & Trim(TxtItemCode) & "%' "
' ReportResults = ReportResults & " And tblReturns.ReceivedDate LIKE '%" & (DATEDIFF(dd, txtItemCodeReportStartDate, txtItemCodeReportEndDate) & "%' "
ReportResults = ReportResults & ")"
End If
End Function
Many Thanks for anyhelp in advance.