compiler syntax error

hortizjr59

Registered User.
Local time
Today, 08:54
Joined
Sep 6, 2011
Messages
30
I tried using this code with a few mods in my database but keep getting a compiler syntax error:

I am using the code as follows:
Private Sub Command135_Click()
Dim strline, strHTML
Dim OL As Outlook.Application
Dim MyItem As Outlook.MailItem
Set OL = New Outlook.Application
Set MyItem = Outlook.Application.CreateItem(olMailItem)

strWhere = "[Improvement No] = " & Me.[Improvement No]
DoCmd.OutputTo acOutputReport, "ReportEmailNoticeofAssigned", acFormatHTML,
"C:\Documents and Settings\hortiz\My Documents\Hector\myreport.html"

Open "C:\Documents and Settings\hortiz\My Documents\Hector\myreport.html" For Input As 1
Do While Not EOF(1)
Input #1, strline
strHTML = strHTML & strline
Loop
Close 1
' If OL2002 set the BodyFormat
If Left(OL.Version, 2) = "10" Then
MyItem.BodyFormat = olFormatHTML
End If
MyItem.HTMLBody = strHTML
MyItem.Display
End Sub
 
What error do you get? What line is it on? Solving a bug is like a crime scene. Supply ALL the evidence, you get a better outcome.
Cheers,
 
Thanks for your reply Lagbolt:

I get a Compile Error: Syntax Error. Actual Screen Results from error message

Private Sub Command135_Click()
Dim strline, strHTML
Dim OL As Outlook.Application
Dim MyItem As Outlook.MailItem
Set OL = New Outlook.Application
Set MyItem = Outlook.Application.CreateItem(olMailItem)
strWhere = "[Improvement No] = " & Me.[Improvement No]
DoCmd.OutputTo acOutputReport, "ReportEmailNoticeofAssigned", acFormatHTML,
"C:\Documents and Settings\hortiz\My Documents\Hector\myreport.html"
Thanks
 
Is this on one line or two lines as it shows here? It may be missing the line continuation character (space-underscore).
 
This...
Code:
DoCmd.OutputTo acOutputReport, "ReportEmailNoticeofAssigned", acFormatHTML,
"C:\Documents and Settings\hortiz\My Documents\Hector\myreport.html"
...has to be on one line. If you want to continue a line you need to use the underscore as a line continuation character, so...
Code:
DoCmd.OutputTo acOutputReport, "ReportEmailNoticeofAssigned", acFormatHTML, _
"C:\Documents and Settings\hortiz\My Documents\Hector\myreport.html"
 
Thanks so much that did take care of my proble. However now I have a new one. The 1st report I printed was record #44 with all is correct info.

I created a new record #45 and entered new information on my report. When I click the button a created to run my email code I was expecting to see my report for record #45 however it gave me record #44 again. For some reason it will not give me the current record on my form. Below is the code I a running error free thanks to your help:

Private Sub Command135_Click()
Dim strline, strHTML
Dim OL As Outlook.Application
Dim MyItem As Outlook.MailItem
Set OL = New Outlook.Application
Set MyItem = Outlook.Application.CreateItem(olMailItem)

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[Improvement No] = " & Me.[Improvement No]
DoCmd.OutputTo acOutputReport, "ReportEmailNoticeofAssigned", acFormatHTML, "C:\Documents and Settings\hortiz\My Documents\Hector\myreport.html"

End If

Open "C:\Documents and Settings\hortiz\My Documents\Hector\myreport.html" For Input As 1
Do While Not EOF(1)
Input #1, strline
strHTML = strHTML & strline
Loop
Close 1
' If OL2002 set the BodyFormat
If Left(OL.Version, 2) = "10" Then
MyItem.BodyFormat = olFormatHTML
End If
MyItem.HTMLBody = strHTML
MyItem.Display
End Sub

Any help will be valued.

Thanks.:confused:
 
I'm not sure about this but I doubt that DoCmd.OputputTo is able to output a filtered report. Note that a report doesn't really support the concept of a 'current' record because there is no capacity to navigate.
What I would do, and others perhaps have a better angle on this, is recreate the querydef on which the report is based and then output the report.
Code might look like...
Code:
[COLOR="Green"]  'create exactly the querydef your report needs[/COLOR]
  currentdb.createquerydef("qYourReportQuery", _
    "SELECT * FROM tYourTable WHERE [Improvement No] = " & Me.[Improvement No])
[COLOR="Green"]  'here your report opens and consumes exactly the querydef you made for it[/COLOR]
  DoCmd.OutputTo acOutputReport, "ReportEmailNoticeofAssigned", acFormatHTML, "C:\Documents and Settings\hortiz\My Documents\Hector\myreport.html"
Does that make sense?
Mark
 
I'm not sure about this but I doubt that DoCmd.OputputTo is able to output a filtered report.
The DoCmd output and send commands won't accept a where condition, a way arround this is to open the report in preview with a where condition active and then use the DoCmd export function like:
Code:
    stDocName = "ReportEmailNoticeofAssigned"
    stFilename ="C:\Documents and Settings\hortiz\My Documents\Hector\myreport.html"
    strWhere = "RecordID=" & Me.RecordID


    DoCmd.OpenReport stDocName, acNormal, , strWhere
    DoCmd.OutputTo acOutputReport, stDocName , acFormatHTML, stFilename
    DoCmd.Close acReport, stDocName
Note:
I put reportname and filename in a variable to prevent typos as they are used more then once.
The variable strWhere need some tweaking to match the actual fieldname.
 
Thanks for all your help.

I added print preview to my code and it is working fine now.

Thanks

:rolleyes:
 

Users who are viewing this thread

Back
Top Bottom