Results 1 to 5 of 5
  1. #1
    sstiebinger is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2015
    Posts
    105

    Error on INSERT INTO string built with VBA

    I'm building out a test database to build proposals from a parts list, and I've run into an issue here when I'm trying to add a part to a proposal.
    I've attached a copy of the database with pricing changed to protect the innocent.



    If you open frmProposal there's a subform with a button to add a part to the proposal.
    That button opens the parts list selector continuous form.... double-clicking any individual line on that selector form should add that line item to the individual proposal.
    However, when I try to click it, my code is spitting back that the query is missing an operator, and I can't for the life of me figure out what I'm missing.

    Any help appreciated.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    You have several issues. One is that you seem to be using variables to determine column names in your SELECT statement. Do you have a column named '1'?

    Another issue is that you are using parenthesis on your SELECT statement incorrectly. I do not see a need for them with that statement, leave them out. Here is an example using INSERT INTO with a SELECT statement.
    Code:
    INSERT INTO TableOne (FieldOne, FieldTwo, FieldThree)
    SELECT FieldName1, Fieldname2, FieldName3
    FROM TableTwo
    WHERE FieldName5 = 200;

  3. #3
    sstiebinger is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2015
    Posts
    105
    The variables are used for hard-coded values, not selected values from the table.
    i.e.

    Code:
    INSERTINTO Movies (Title, Director, Cost, Profits)
    SELECT'Star Wars', name,50000,1000000
    FROM Directors WHERE name ='Lucas'
    Where the only item actually populated from "Directors" would be NAME... the other items just being values inserted into the fields.

  4. #4
    sstiebinger is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2015
    Posts
    105
    So I got rid of the Parens which helped by changing the error message.
    This led me to realize that I had missed a comma between PartID and InstallationHours.

    The solution is working now.

    Thanks for the help.

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Glad you were able to work through it.

    In case you are not aware of debugging your SQL as a troubleshooting method ...
    http://www.baldyweb.com/immediatewindow.htm

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

Similar Threads

  1. Replies: 2
    Last Post: 04-05-2015, 06:06 PM
  2. Replies: 5
    Last Post: 12-19-2014, 04:38 PM
  3. Replies: 11
    Last Post: 05-01-2014, 11:56 AM
  4. Replies: 3
    Last Post: 09-05-2012, 10:23 AM
  5. Replies: 3
    Last Post: 01-05-2012, 10:47 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