Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Microsoft Access VBA Outlook

Posted on 2012-04-01
4
Medium Priority
?
728 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:Eileen Murphy
  • 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:Eileen Murphy
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 2000 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:Eileen Murphy
ID: 37794336
Thanks a lot!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
Take a look at these 6 Outlook Email management tools which can augment the working and performance of Microsoft Outlook to give you a more rewarding emailing experience.
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

916 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