need a date filter to open report

need a date filter to open report

 = "[DateRequired] =#" & [Formulieren]![Workorders by Customer].[Workorders by Customer Subform].[Form]![DateRequired] & "#" 

Open in new window

mvdwalAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
so, what is the problem?

to open the report with a date filter

dim dteFilter as date
dteFilter = "[DateRequired] =#" & [Formulieren]![Workorders by Customer].[Workorders by Customer Subform].[Form]![DateRequired] & "#"

'open report with this command line
docmd.openreport "ReportName",acviewPreview , , dteFilter



.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gustav BrockCIOCommented:
You may need a properly formatted filter expression:

Dim DateFilter As String

DateFilter = "[DateRequired] =#" & Format([Formulieren]![Workorders by Customer].[Workorders by Customer Subform].[Form]![DateRequired], "yyyy\/mm\/dd") & "#"

or:

DateFilter = "[DateRequired] =#" & Format([Forms]![Workorders by Customer].[Workorders by Customer Subform].[Form]![DateRequired], "yyyy\/mm\/dd") & "#"

/gustav
mvdwalAuthor Commented:
Thanks,

I have used the date filter

DateFilter = "[DateRequired] =#" & Format([Forms]![Workorders by Customer].[Workorders by Customer Subform].[Form]![DateRequired], "yyyy\/mm\/dd") & "#"

I need to filter the report at two more fields
CustomerID (is a number value)
and PO number (is a text value)

It's driving me crazy. I'll get a 2501 error

Dim MyFilter As String
Dim MyextraFilter As String
Dim MyPath As String
Dim MyFilename As String
Dim strSql As String

Const cInvalidDateError As String = "You have entered an invalid date."
Dim strWhere As String
    Dim strError As String
   
    strWhere = "1=1"
         
         ' If datum
    If Not IsNull([Workorders by Customer Subform].Form![DateRequired]) Then
        'Add the predicate
   strWhere = "Workorders.[DateRequired] =#" & Format([Workorders by Customer Subform].Form![DateRequired], "dd\/mm\/yyyy") & "#"
    End If
         
       ' If Customer
 If Not IsNull([Forms]![Workorders by Customer].[CustomerID]) Then
        'Add the predicate
     strWhere = strWhere & " AND " & "Workorders.[CustomerID] = " & [Forms]![Workorders by Customer].[CustomerID] & ""
   End If


 If Len(strWhere) > 0 Then
    strSql = "SELECT * FROM BatchPackinglistDateqry  WHERE " & strWhere
    End If





If Len(Dir("S:\003_Pakbonnen\pdf\" & Me!CompanyName, vbDirectory)) = 0 Then
   MkDir "S:\003_Pakbonnen\pdf\" & Me!CompanyName
End If

MyPath = "S:\003_Pakbonnen\pdf\" & Me!CompanyName & "\"
MyFilename = Format(Now(), "yymmdd") & "-" & "Pakbon Batch-" & "-" & Me!CompanyName & "-PO-" & [Workorders by Customer Subform].Form![PurchaseOrderNumber] & ".pdf"

'Let's print and save. Once you see it works, you can change True to False so that the file created is not opened after completion.
 DoCmd.OpenReport ReportName:="BatchPackinglist_de", View:=acViewPreview, WhereCondition:=strWhere
DoCmd.OutputTo acOutputReport, "", acFormatPDF, MyPath & MyFilename, False

'Let's close our previewed report
If Err <> 2501 Then
        MsgBox Err.Description
    End If


  
  
DoCmd.Close acReport, "BatchPackinglist_de"

Open in new window

Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

Gustav BrockCIOCommented:
That would be:

     strWhere = strWhere & " AND " & "Workorders.[PO Number] = '" & [Forms]![Workorders by Customer].[PO Number] & "'"

/gustav
mvdwalAuthor Commented:
Thanks  a lot for your help but I think my total code is wrong. How can I filter on three fields in a sub report, with an vb event procedure? If I filter the report directly in the query on the subform it works.

What is the easiest method to filter more than just one filter?
Gustav BrockCIOCommented:
That depends. It is perfectly OK to filter by the "where" string option. If a filter works in the query source, so will it as a filter string passed as a parameter when opening the report.

/gustav
mvdwalAuthor Commented:
Thanks guys!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.