Solved

Microsoft Access VBA Outlook

Posted on 2012-04-01
4
715 Views
Last Modified: 2012-04-01
I have used this code many times with no issues --- not sure why I'm getting "Compile Error - Expected function or variable." below where I have the <<<<<< arrows...

Any idea what's wrong with the code?


Public Function MySendEMail()

    If strMailAddress = "" Or IsNull(strMailAddress) Then
        MsgBox "No e-mail address on file.", vbInformation
        Exit Function
    End If

    Dim db As DAO.Database
    Dim td As DAO.TableDef
    Dim rs As DAO.Recordset
    Dim maillist As DAO.Recordset
   
    Dim strCriteria As String, lngClientID As Long, EMailAddressOnFile As Boolean
    Dim theReport As String, intCount As Integer
   
   
    Set db = CurrentDb()

    strCriteria = "[CID]=" & lngID
   
    Set td = db.TableDefs("tblCustomer")
    Set rs = td.OpenRecordset(dbOpenDynaset, dbSeeChanges)
   
    rs.FindFirst strCriteria
    If rs.NoMatch = False Then

    Else
        MsgBox "No matching Borrower record. Try again.", vbInformation
        exit function
    End If
    rs.Close
   
    Set olapp = New Outlook.Application
    Set olMail = olapp.CreateItem(olMailItem)
    Set olNs = olapp.GetNamespace("MAPI")
    olNs.Logon

    With olMail
        .To = strMailAddress
        .Subject = "Correspondence from Chase"
        .BodyFormat = olFormatHTML
        '.Attachments.Add "c:\database temp\TransportOneInvoice.pdf"
        .HTMLBody = "<HTML><BODY> Dear " & strSalutation & " <br> <br> " & _
        strMemo & " <br> <br> " & _
        strRegarding & " <br> <br> " & _
        strMemo1 & " <br> <br> " & _
        strMemo2 & " <br> <br> " & _
        strMemo3 & " <br> <br> " & _
        strMemo4 & " <br> <br> " & _
        strClose & " <br> <br> " & _
        strSignatureLine & " <br> <br> " & _
       .Display                                      <<<<<<<<------------------------------------
    End With

    olNs.Logoff
           
    Set db = Nothing
    Set td = Nothing
    Set rs = Nothing

End Function
0
Comment
Question by:Ei0914
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37793816
1. do a compact and repair of the app db
     office button > manage > compact and repair


2. check you references, make sure that there are no listed ref prefix with "MISSING"
if you find one uncheck then click OK,  then do  a DEBUG > Compile, make sure that there are no errors raised

post back the result.
0
 

Author Comment

by:Ei0914
ID: 37793882
No missing references. I created a new db and imported all the objects because I got a compatibility error (I created the app initially on a PC with 2010) -- this PC has 2007 -- so I wanted to see if that would fix the issue.

I am still getting the same error. When I debug/compile -- I am getting the same error.
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 37794231
I think you have one too many line continuation characters in there.

Try this:


Public Function MySendEMail()

    If strMailAddress = "" Or IsNull(strMailAddress) Then
        MsgBox "No e-mail address on file.", vbInformation
        Exit Function
    End If

    Dim db As DAO.Database
    Dim td As DAO.TableDef
    Dim rs As DAO.Recordset
    Dim maillist As DAO.Recordset
   
    Dim strCriteria As String, lngClientID As Long, EMailAddressOnFile As Boolean
    Dim theReport As String, intCount As Integer
   
   
    Set db = CurrentDb()

    strCriteria = "[CID]=" & lngID
   
    Set td = db.TableDefs("tblCustomer")
    Set rs = td.OpenRecordset(dbOpenDynaset, dbSeeChanges)
   
    rs.FindFirst strCriteria
    If rs.NoMatch = False Then

    Else
        MsgBox "No matching Borrower record. Try again.", vbInformation
        exit function
    End If
    rs.Close
   
    Set olapp = New Outlook.Application
    Set olMail = olapp.CreateItem(olMailItem)
    Set olNs = olapp.GetNamespace("MAPI")
    olNs.Logon

    With olMail
        .To = strMailAddress
        .Subject = "Correspondence from Chase"
        .BodyFormat = olFormatHTML
        '.Attachments.Add "c:\database temp\TransportOneInvoice.pdf"
        .HTMLBody = "<HTML><BODY> Dear " & strSalutation & " <br> <br> " & _
        strMemo & " <br> <br> " & _
        strRegarding & " <br> <br> " & _
        strMemo1 & " <br> <br> " & _
        strMemo2 & " <br> <br> " & _
        strMemo3 & " <br> <br> " & _
        strMemo4 & " <br> <br> " & _
        strClose & " <br> <br> " & _
        strSignatureLine & " <br> <br> "   '***** I  took off the &_ from this line.
       .Display                                     ' <<<<<<<<------------------------------------
    End With

    olNs.Logoff
           
    Set db = Nothing
    Set td = Nothing
    Set rs = Nothing

End Function
0
 

Author Closing Comment

by:Ei0914
ID: 37794336
Thanks a lot!
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Changing a few Outlook Options can help keep you organized!
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question