Results 1 to 4 of 4
  1. #1
    dr223 is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2010
    Posts
    20

    Insert to a table

    Hi,



    On my form (frmMain) I have 4 combo boxes, cmbcr1, cmbcr2, cmbcr3 and cmbcr4.

    I have also a submit button..

    When clicked I want to pass the value selected from the combo boxes to a TblTemp.. How can I update this code;


    DoCmd.RunSQL "INSERT INTO TblTemp(Que1W,Que2W, Que3W,Que4W) SELECT .......


    N/B: Que1W = will store the value from cmbcr1
    Que2W = will store the value from cmbcr2 etc



    Thanks

  2. #2
    pdebaets is offline Competent Performer
    Windows Vista Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Los Angeles
    Posts
    235
    First, you can bind a form to a table and make this process much easier.

    If you MUST use a query to insert your records, then if your combo boxes return numeric values try

    CurrentDB.Execute "INSERT INTO TblTemp(Que1W,Que2W, Que3W,Que4W) VALUES (" & cmbcr1 & "," & cmbcr2 & "," & cmbcr3 & "," & cmbcr4 & ");", dbseechanges + dbfailonerror

    If they return text strings, then try


    CurrentDB.Execute "INSERT INTO TblTemp(Que1W,Que2W, Que3W,Que4W) VALUES ('" & cmbcr1 & "','" & cmbcr2 & "','" & cmbcr3 & "','" & cmbcr4 & "');", dbseechanges + dbfailonerror

  3. #3
    dr223 is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2010
    Posts
    20
    It's text so i used:

    DoCmd.RunSQL "INSERT INTO TblTemp(Que1W,Que2W, Que3W,Que4W) VALUES ('" & cmbcr1 & "','" & cmbcr2 & "','" & cmbcr3 & "','" & cmbcr4 & "');", dbseechanges + dbfailonerror


    Message:

    You are about to append 1 row(s).
    Once you click Yes, you can't use.....

    I selected - Yes.

    Open the table I see a blank Row created with no data... Why?

    Many thanks

  4. #4
    pdebaets is offline Competent Performer
    Windows Vista Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Los Angeles
    Posts
    235
    You can turn off the Access option "Confirm Action Queries".

    Was anything in your combo boxes?

    Please note that I strongly recommend using a bound form, instead of the approach you are using.

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

Similar Threads

  1. Replies: 25
    Last Post: 01-29-2013, 08:49 AM
  2. Replies: 2
    Last Post: 12-20-2011, 07:33 AM
  3. Replies: 1
    Last Post: 12-28-2010, 11:24 AM
  4. Replies: 2
    Last Post: 12-22-2010, 01:46 PM
  5. Replies: 0
    Last Post: 02-24-2010, 12:56 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