Results 1 to 6 of 6
  1. #1
    sanderson is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    64

    SendMessage (FileSavePath, txtEmpID) looking for = Compile Error

    Hello:



    SendMessage is a sub (VBA Access 2013)

    It turns red and says Compile error: Expected: =

    If I remove the second item and just call FileSavePath, the code runs great!

    Thanks in advance for any help!

    Code:
    Private Sub SendMessage(FileSavePath As String, txtempid As String)
        Dim appOutLook As Outlook.Application
        Dim MailOutLook As Outlook.MailItem
    
    
        'Dim txtempname As String
        'txtempname = DLookup("name", "dbo_empbasic", "empid = '" & txtEmpID & "' ")
        'MsgBox ("txtempname: " & txtempname)
        
        Set appOutLook = CreateObject("Outlook.Application")
        Set MailOutLook = appOutLook.CreateItem(olMailItem)
    
    
        With MailOutLook
            .BodyFormat = olFormatRichText
            .To = "sanderson@metromachine.com"
            ''.cc = ""
            ''.bcc = ""
            .Subject = "Weekly Timecard for "
            .HTMLBody = ""
            '.HTMLBody = "Attached is the timecard for " & txtempname & ", employee number " & txtempno & " for the week of " & CStr(datPeriodStart) & " through " & CStr(datPeriodEnd) & "."
            .Attachments.Add (FileSavePath)
            .Send
            '.Display    'Used during testing without sending (Comment out .Send if using this line)
                
        End With
      
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    What line causes error? What is 'second item'?

    Is empid a text or number type field?

    Name is a reserved word. Should not use reserved words as field names.

    Is there possibility the DLookup will not find a match?

    Try:

    txtempname = Nz(DLookup("[name]", "dbo_empbasic", "empid = '" & txtEmpID & "'"),"")

    Where are txtempno and datPeriodStart and datPeriodEnd coming from? If those are VBA variables, they are not declared and set.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    sanderson is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    64
    When I add the second field in both places, I get the compile error "expected =" When I try to run, I get a Compile error, "Syntax Error"

    Both fields are text, and the second is the employee number, also text.

    Nz. good idea.

    Thanks. Let me know if you have any ideas.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    I am lost. Add in what both places?

    Did not answer my last question in previous thread.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    sanderson is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    64
    Is empid a text or number type field? text

    Name is a reserved word. Should not use reserved words as field names. Unfortunately it exists in a sql table and I cannot change it.

    Is there possibility the DLookup will not find a match? I believe dLookup will work great, however it is remmed out and not part of this problem. I cannot test it until I have an employee number to feed it with.


    Both places refers to the sub, and the sub call.

    Thanks!



  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    I am lost. Exactly what line in the posted code errors?

    I still don't know where txtempno and datPeriodStart and datPeriodEnd are coming from.

    If you use reserved words as names or if names have spaces or special characters, enclose in [].
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 07-24-2013, 02:01 PM
  2. Compile Error: Syntax Error in DoCmd.RunSQL Statement
    By Evilferret in forum Programming
    Replies: 1
    Last Post: 08-27-2012, 12:32 PM
  3. Replies: 2
    Last Post: 06-23-2012, 11:59 PM
  4. Replies: 7
    Last Post: 06-08-2012, 09:55 PM
  5. Replies: 6
    Last Post: 09-28-2011, 09:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums