Printing Report by limiting any word in a Reference

Sunnylei

Registered User.
Local time
Today, 01:47
Joined
Mar 5, 2011
Messages
87
I'm trying to print a report by filter any word which is contained in a contract reference range. I create a form name as "frmWhatContractRef", and I added a unbound text box on the form and a command button named as cmdPreview on the form. The code:

Code:
Private Sub cmdPreview_Click()
'On Error GoTo Err_Handler 'Remove the single quote from start of this line once you have it working.
'Purpose: Filter a report to a Contract Reference range.
Dim strWhere As String
Dim strContractRefField As String
strContractRefField = "[Contract Ref]"
'Build the filter string.
If Not IsNull(Me.txtStartContractRef) Then
strWhere = strWhere & "([Contract Ref] = """ & Me.txtStartContractRef & """) AND "
End If
If Not IsNull(Me.txtEndContractRef) Then
strWhere = strWhere & "([Contract Ref] = """ & Me.txtEndContractRef & """)"
End If
'Close the report if already open: otherwise it won't filter properly.
If CurrentProject.AllReports(strReport).IsLoaded Then
DoCmd.Close acReport, strReport, acSaveNo
End If
'Open the report.
DoCmd.OpenReport "rptPurchaseContractRef", acViewPreview, , strWhere
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "Cannot open report"
End If
Resume Exit_Handler
 
End Sub

I also added two text boxes on Report "rptPurchaseContractRef:
Code:
=[Forms].[frmWhatABContractRef].[txtStartContractRef]
=[Forms].[frmWhatABContractRef].[txtEndContractRef]

But I must enter correct reference, otherwise the report wouldn't filter out the reference if I enter one of word which is contained in the reference. How to let it work, can anyone help?:confused:
 

Users who are viewing this thread

Back
Top Bottom