Results 1 to 8 of 8
  1. #1
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110

    Access VBA Email Syntax Error

    Im using Access with the outlook reference library enabled.

    I'm trying to play with automating an email using VBA, Ive done this a few times, but not with a Dlookup in the middle of a sentence. I am trying to get the schedule type from my lookup from a query and the msg part returns a syntax error. What punctuation is wrong for this to not work?



    Code:
    Private Sub btnReminder_Click()Dim Msg As String
    
    
    Msg = "Hi,<P>" & _
    "As part of our BRC the following " DLookup("[ScheduleTypes]", "[QryScheduleOverdue]", "ScheduleID=" & Me.ScheduleID )" is overdue. <P>" & _
    "<P>" & _
    "Please update me with the date that this task will be completed and submitted to me by the close of play tomorrow. <P>" & _
    "<P>" & _
    "If I do not hear back from you by the close of play tomorrow then I will have to raise this non-conformity with the MD. <P>" & _
    "<P>" & _
    "<P>" & _
    "<P>" & _
    "Kind Regards"
    
    
    Dim O As Outlook.Application
    Dim M As Outlook.MailItem
    
    
    Set O = New Outlook.Application
    Set M = O.CreateItem(olMailItem)
    
    
    With M
            .BodyFormat = olFormatHTML
            .HTMLBody = Msg
            .To = DLookup("[WarehouseManager]", "[tblContactemails]")
            .CC = DLookup("[DeputyWarehouseManager]", "[tblContactemails]")
            .Subject = [ScheduleTypes] & " Overdue "
            .Display
    End With
    
    
    Set M = Nothing
    Set O = Nothing
    End Sub

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Do not try to be clever.
    Get each part of your data, then you can check it with a debug.print or just hover over it.
    You obtained the scheduletype once but did not store it? , so you would need to retrieve it again.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You have to concatenate the variable input - whether or not you set a declared variable to the DLookup() retrieved value.
    Code:
    "As part of our BRC the following " & DLookup("[ScheduleTypes]", "[QryScheduleOverdue]", "ScheduleID=" & Me.ScheduleID) & " is overdue. <P>" & _
    How is ScheduleID selected - a combobox? A properly constructed combobox could eliminate need for DLookup().

    What data are you working with - what is "close of play"?
    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.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    On my phone admittedly, but I thought the the issue was .Subject ? with nothing for ScheduleTypes?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Multiple issues with code. Lack of concatenation is just one.

    If [ScheduleTypes] is already a field/control on form, why do you need DLookup() to find it?
    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.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    @June7

    'Close of play' is a term for the end of the working day.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Okay, on this side of the pond we just say "end of day".

    Does calling the workday "play" make it more appealing to be there?
    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.

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Same rubbish as 'touch base' etc.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. SYNTAX ERROR Summing Columns in Access SQL
    By pnpez in forum Programming
    Replies: 5
    Last Post: 05-25-2021, 02:57 PM
  2. Access Syntax Error
    By reddsable in forum Programming
    Replies: 1
    Last Post: 01-25-2020, 06:35 AM
  3. Gmail signature with email address syntax error
    By Gina Maylone in forum Access
    Replies: 2
    Last Post: 01-26-2016, 07:41 AM
  4. Syntax Error in my Access SQL Query
    By hellfire45 in forum Access
    Replies: 1
    Last Post: 03-10-2015, 01:40 PM
  5. Access 2007 syntax error in query
    By ivanver in forum Queries
    Replies: 3
    Last Post: 04-23-2011, 09:41 AM

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