Results 1 to 6 of 6
  1. #1
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    136

    Insert into not working

    I am trying to execute the below but when I go and view the table "tblRecipientsForCustomEmail", it's empty.
    Is there anything that looks wrong in my sql code?
    I checked the spelling too and even put a debug.print statement to see what the SQL statement looks like.
    Code:
    dim sSQL = ""
    
    sSQL = "INSERT INTO tblRecipientsForCustomEmail"
    sSQL = sSQL & vbNewLine & "SELECT L.EntityName, r.Email, L.BTMU_Relationship_Office"
    sSQL = sSQL & vbNewLine & "FROM Limit_Exposure_Report_All L, tblRecipients r"
    sSQL = sSQL & vbNewLine & "WHERE L.BTMU_Relationship_Office = r.[Relationship Office]"
    sSQL = sSQL & vbNewLine & "AND L.EntityName IN (" & sCompanies & ")"
    
    Debug.Print sSQL
    CurrentDb.Execute sSQL


  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Stop using SQL code and use a query.
    it won't get the SQL wrong and will tell you WHAT is wrong .

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    when I go and view the table "tblRecipientsForCustomEmail", it's empty.
    Did you already have the table open and just not know that you have to refresh the view?
    You copied the output and pasted into a new query and tried to run it and nothing happens?
    I would not use .Execute without dbFailOnError. Is there a reason why you don't?
    CurrentDb.Execute sSQL, dbFailOnError
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    What does sCompanies look like?

    And taking a step back, based on your table name, could you not simply query the email addresses for the email routine ?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    mp3909 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    136
    I was making the wrong connection in the tables of my sql query.
    All fixed now thank you

  6. #6
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    NOTE: you cannot declare a variable like this
    Code:
    Dim sSQL = ""
    It MUST be like this
    Code:
        Dim sSQL As String
    
        sSQL = ""

    But you can declare constants like this
    Code:
        Const timmy As Long = 210865

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

Similar Threads

  1. CurrentDB.Execute insert working just once
    By krausr79 in forum Access
    Replies: 4
    Last Post: 10-07-2015, 12:04 PM
  2. INSERT INTO code not working properly.
    By Alphix in forum Forms
    Replies: 8
    Last Post: 11-12-2014, 04:10 PM
  3. Replies: 5
    Last Post: 05-22-2012, 04:15 PM
  4. Working on an SQL Insert / Update combined
    By robsworld78 in forum Programming
    Replies: 0
    Last Post: 02-23-2012, 10:24 PM
  5. why isn't this insert into working?
    By token_remedie in forum Queries
    Replies: 3
    Last Post: 09-21-2011, 09:14 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