Garousi
Garousi

Reputation: 11

VBA Compile Error: expected =

I get an error for my code:

compile error: Expected: =

DoCmd.OutputTo (acOutputReport, _
    ReportName & " " & Load, _
    acFormatPDF, _
    "\\drive\Reports\" & ReportName & " " & Load & " " & Year(Date) & Month(Date) & Day(Date)& ".pdf")

I have Access front-end and SQL-Server backend.

What do I need to do to fix this? I am still a beginner with VBA.

Upvotes: 1

Views: 5901

Answers (1)

Olivier Jacot-Descombes
Olivier Jacot-Descombes

Reputation: 112352

You must call Sub procedures without parameter parentheses ( ) in VBA.

DoCmd.OutputTo acOutputReport, _
    ReportName & " " & MyLoad, _
    acFormatPDF, _
    "\\drive\Reports\" & ReportName & " " & MyLoad & " " & _
        Year(Date) & Month(Date) & Day(Date) & ".pdf"

Also Load is a reserved word in VBA. It is Sub Load(Object As Object). Use another identifier.


The compile error "Expected: =" may seem awkward, but it makes sense, since parentheses are used for Function calls. I.e., VBA is expecting something like this

x = MyFunc(...)

Upvotes: 3

Related Questions