Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    jamin14 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Posts
    17

    SQL Insert into


    I want to use insert into attached to one of my buttons to transfer from one subform to another. has any1 got any example codes because mine just come up with errors

    thank you

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Why don't you post your code and we'll fix it?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jamin14 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Posts
    17
    Private Sub Command22_Click()

    "InsertInto F_Order_Line_Subform" _
    & "(ProductID1) Values" _
    "(ProductID),"
    End SUB

    this is all i have sorry i'm a complete beginner

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    For starters, with SQL you don't insert into the subform, you insert into the underlying table. Second, you've just got a string there; you haven't done anything with it. It would look like:

    CurrentDb.Execute "INSERT INTO..."

    Presuming the value is coming from the current form you'd have to concatenate any such values, like:

    "...VALUES(" & Me.TextboxName & ")"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    jamin14 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Posts
    17
    Private Sub Command22_Click()
    DoCmd.SetWarnings False '..cancel system warnings
    DoCmd.RunSQL "INSERT INTO F_Order_line_subform (ProductID1,Text14,Description,,Price)" _
    & " VALUES (" & [ProductID] & ", '" _
    & [Category] & "' , '" _
    & [Description] & "' , '" _
    & [Price] & " ') ;"
    Forms![F_Order_line_subform].[T_Product subform].Requery

    this is my improved code but i'm getting a runtime error 3134 basically a syntax error any help with this would be greatly appreciated

    thanks

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    For starters, the two commas together would be a problem. Is "F_Order_line_subform" really the name of a table? It appears to be a subform. Is "Text14" really the name of a field in the table? As I said, with SQL you don't insert into a form, you insert into a table. If you want to insert directly into a form, you can't use SQL.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    jamin14 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Posts
    17
    Private Sub Command22_Click()
    DoCmd.SetWarnings False
    MsgBox "INSERT INTO F_Order_line_subform (ProductID1, Text14, Description)" _
    & " VALUES (" & [ProductID] & ", '" & [Category] & _
    "', '" & [Description1] & "');"

    DoCmd.RunSQL "INSERT INTO F_Order_line_subform(ProductID1, Text14, Description)" _
    & " VALUES (" & [ProductID] & ", '" & [Category] & _
    "', '" & [Description1] & "');"
    End Sub

    now it says it cannot find target table ! any help would be greatly appreciated

    thanks

  8. #8
    jamin14 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Posts
    17
    Private Sub Command22_Click()
    DoCmd.SetWarnings False
    MsgBox "INSERT INTO T_Order_line (OrderID, ProductID)" _
    & " VALUES (" & [OrderID] & ", '" & [ProductID] & "');"

    DoCmd.RunSQL "INSERT INTO T_Order_line (OrderID, ProductID)" _
    & " VALUES (" & [OrderID] & ", '" & [ProductID] & "');"

    End Sub

    i ve simplified it and put it to insert into a table but i am getting an error saying "microsft office access can't find the feild 'l' referred to in your expression

    sorry to keep posting but your help has been great

    thanks

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Where are you trying to get the values from? Presuming a form, and the same form this code is running on, try this

    & " VALUES (" & Me.OrderID & ", '" & Me.ProductID & "');"

    Is ProductID a text data type in the table?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    jamin14 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Posts
    17
    Quote Originally Posted by pbaldy View Post
    Where are you trying to get the values from? Presuming a form, and the same form this code is running on, try this

    & " VALUES (" & Me.OrderID & ", '" & Me.ProductID & "');"

    Is ProductID a text data type in the table?

    oRDER ID value comes from a form while product id is from a subform within the form.

    product id is a number data type

    me. did not work unfortunately

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If product ID is a number, you don't want the single quotes surrounding the value. Can you post the db?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    jamin14 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Posts
    17
    thiss should work

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I don't see that code anywhere in this sample. Did you try without the single quotes:

    & " VALUES (" & Me.OrderID & ", " & Me.ProductID & ");"

    Since the values on are different forms, you'll need to adjust the form references relative to where you intend to run the code from:

    Forms Refer to Form and Subform properties and controls
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    jamin14 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Posts
    17
    Quote Originally Posted by pbaldy View Post
    I don't see that code anywhere in this sample. Did you try without the single quotes:

    & " VALUES (" & Me.OrderID & ", " & Me.ProductID & ");"

    Since the values on are different forms, you'll need to adjust the form references relative to where you intend to run the code from:

    Forms Refer to Form and Subform properties and controls
    i changed my code but still get errors

    Private Sub Command22_Click()
    DoCmd.SetWarnings False
    MsgBox "INSERT INTO T_Order_line (Description, ProductID)" _
    & " VALUES (" & Me.Description1 & ", " & Me.ProductID1 & ");"


    DoCmd.RunSQL "INSERT INTO T_Order_line (Description, ProductID)" _
    & " VALUES (" & Me.Description1 & ", " & Me.ProductID1 & ");"

    End Sub


    i get on error runtime error 3075 , missing operator in expression sp1

    any help would be appreciated

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Is sp1 one of the values you're trying to insert? If so, that value is text and would need to be surrounded by single quotes. I think I saw both as numeric in the table though, so this could indicate a different problem. If you can upload a sample with this code in it, it would be easier to debug.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Insert only permission?
    By wordracr in forum Security
    Replies: 1
    Last Post: 01-14-2010, 04:48 PM
  2. Stumped on an INSERT
    By Elisa in forum Programming
    Replies: 1
    Last Post: 12-26-2009, 10:49 AM
  3. Just insert new data
    By watzmann in forum Access
    Replies: 1
    Last Post: 11-29-2009, 11:48 AM
  4. help with insert
    By jamie in forum Access
    Replies: 1
    Last Post: 11-16-2009, 06:02 AM
  5. automatic row insert
    By Jerry8989 in forum Forms
    Replies: 7
    Last Post: 09-29-2009, 06:50 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