Results 1 to 6 of 6
  1. #1
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    Question INSERT INTO query in VBA

    I'm confused. I thought this would work just fine but I keep getting an error stating "Query input must contain at least one table or query." I must be missing something because I feel pretty confident that Table1 is my table....



    Code:
    mySQL = "INSERT INTO Table1 (LastUpdateUser, LastUpdateDate) VALUES ('" & varUser & "', #" & varDate & "#) WHERE ([PriID] =  '" & varID & "')"
        CurrentDb.Execute mySQL, dbFailOnError

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    mySQL = "INSERT INTO Table1 (LastUpdateUser, LastUpdateDate) VALUES ('" & varUser & "', #" & varDate & "#) WHERE ([PriID] = '" & varID & "')"

    you should not use a where clause after values ().

  3. #3
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Ok, where should the "WHERE" go then? When I put it inbetween the "INSERT INTO" and "VALUES" I got a Syntax error.

    Code:
    mySQL = "INSERT INTO LevyTable (LastUpdateUser, LastUpdateDate) WHERE ([PriEntityID] =  '" & varEntityID & "') VALUES ('" & varUser & "', #" & varDate & "#)"
        CurrentDb.Execute mySQL, dbFailOnError
    Returns "Syntax error in INSERT INTO statement"...

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    you don't need a where clause since you are simply adding one record with values

  5. #5
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Do you want to update a record in table1? then you need an update query, not insert into.

  6. #6
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Ok, then I am going about this all wrong. I need to run an UPDATE SQL, not INSERT INTO....

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

Similar Threads

  1. INSERT query: insert new data only
    By drh in forum Access
    Replies: 2
    Last Post: 04-04-2014, 05:31 PM
  2. Access insert into query...
    By xmetisx in forum Queries
    Replies: 2
    Last Post: 04-06-2010, 02:27 PM
  3. Replies: 0
    Last Post: 02-24-2010, 12:56 AM
  4. help with insert
    By jamie in forum Access
    Replies: 1
    Last Post: 11-16-2009, 06:02 AM
  5. Insert Query output into a table
    By ammu_sridhar in forum Programming
    Replies: 1
    Last Post: 06-12-2009, 01:09 AM

Tags for this Thread

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