Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Code/SQL experts help..

    I run this code from a button on a form.. When I run the code it gives me an error 'Run-Time error '3134' Syntax error in INSERT INTO statement.. Obviously the error deals with the INSERT INTO part of the SQL statement, but I checked the "SELECT" part of the SQL and it does pull the data I need.. So that part is correct.. Program is a string for the name of the table I want to insert the data into.. Appendtable is a string for the name of the table I want to select the data from... I even tried building the SQL as an append query and using that SQL but I got the same error.. Any thoughts? Thanks

    Dim Program As String
    Dim AppendTable As String
    Program = pgmtbl
    AppendTable = Program & "Resolutiontbl"

    DoCmd.RunSQL "INSERT INTO " & Program & "SELECT " & AppendTable & ".[Voucher#]," & AppendTable & ".[First Name]," & AppendTable & ".[Last Name]," & AppendTable & ".[Appt#] FROM " & AppendTable & " [img]/w3timages/icons/clever.gif[/img][img]/w3timages/icons/clever.gif[/img]

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Code/SQL experts help..

    Hi Gary,
    Firstly, unless pgmtbl is a variable, you need to change your code to read:
    Program = "pgmtbl"
    It's also unclear on my screen how you've ended the SQL statement - it looks like your code ends in & "
    It needs to end in ";" instead I think. I'd also check to make sure you've got a space before the SELECT statement (otherwise your string becomes 'INSERT INTO pgmtblSELECT' which might throw Access off track.
    Hope that helps!
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code/SQL experts help..

    Thanks Rory. It was getting late in the day when I posted that.. I was getting pretty tired.. I hope you've been well and thanks again..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •