Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    cwwaicw311 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    75

    VB code not working


    inTable = "INSERT INTO TransactionTable (Date, Quantity, Remark, ItemID, PartID) VALUES("
    inTable = inTable & "#" & Me.Date & "# , " & Me.Quantity & " , " & Me.Problem & " , " & Me.ItemType & " , " & Me.PartNumber & " );"
    DoCmd.SetWarnings False
    DoCmd.RunSQL inTable
    DoCmd.SetWarnings True

    When i execute this code it say error in INSERT INTO statement... Can anyone help me solve it...?? Thank...

  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    I have assumed that
    Quantity=Number
    ItemID=Number
    PartID=Number

    inTable="INSERT INTO TransactionTable (Date, Quantity, Remark, ItemID, PartID) Values("
    inTable=inTable & "#" & Me.date & "#," & Me.Quantity & ",'" & Me.Problem & "'," & Me.Itemtype & "," & Me.PartNumber & ");"

    The problems in the code are highlighted in red.

    nTable = "INSERT INTO TransactionTable (Date, Quantity, Remark, ItemID, PartID) VALUES("
    inTable = inTable & "#" & Me.Date & "# , " & Me.Quantity & " , " & Me.Problem & " , " & Me.ItemType & " , " & Me.PartNumber & " );"



    Remember if you take values from controls like textboxes and comboboxes and the values are strings then they have to be enclosed in ''

    e.g. "'" & Me.Text1 & "'"

    Dates "#" & Me.Text1 & "#"

    Mark the the thread if this solves your problem.

  3. #3
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    is your problem solved if yes please mark this thread solved.

  4. #4
    cwwaicw311 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    75
    Hi,

    Currently doing a system almost as the same as the last one but without all those calculation. However, there are 2 problem i cant solve in this new system which is running smoothly on the old system. I follow the code but it still not working.

    1. Is the requery part of the machine but this time is part number. Whereby different Item have different part number.
    2. The save button. I tried to enclose with the specific symbol but still cant do it. N I cant save any transaction.

    I have attached the database on this thread. Thank...

  5. #5
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    can you specify the problem is in which form.

  6. #6
    cwwaicw311 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    75
    TPMSnSEDONA

  7. #7
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    I am attaching the mdb just check if the problem is resolved.

  8. #8
    cwwaicw311 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    75
    Hi,

    The problem is solved only if the item is choose by the user at the Item Type column. I wanted it to be like my last system. Whereby, when the item is choose from the main menu, the form is open then the item type would automatically prompt out the item which the user choose from the main menu.
    I manage to do that, but the requery is not working as the partNumber column do not show anything.

  9. #9
    cwwaicw311 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    75
    Hi,

    I have solved the problem regarding the requery. Could you help me solve the problem on the INSERT INTO statement. I tried but i cant manage to do it because I do not want my column to have control source coz all item will be automatically enter into the table without even need to save. Hence, that would cause error. So it is best that i have a button with the INSERT INTO statement with it. So that when click on the button the transaction would oni be insert into the table

  10. #10
    cwwaicw311 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    75
    Hi,

    I try myself on the INSERT INTO statement. But still got some issue on it.

    Private Sub Done_Click()
    Dim inTable As String
    inTable = "INSERT INTO TransactionTable (Date,Quantity,Remark,PartID,ItemID) VALUES ("
    inTable = inTable & " #" & Me.Date & "#, " & Me.Quantity & "," & " '" & Me.Remark & "', " & Me.PartNumber & ", " & Me.ItemType & ");"
    DoCmd.SetWarnings False
    DoCmd.RunSQL inTable
    DoCmd.SetWarnings True
    End Sub

    I not sure wat is the problem. I also add in the symbol for date and combo box data.

  11. #11
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    inTable = "INSERT INTO TransactionTable (Date,Quantity,Remark,PartID,ItemID) VALUES ("
    inTable = inTable & "#" & Me.Date & "#," & Me.Quantity & "," & "'" & Me.Remark & "'," & Me.PartNumber & "," & Me.ItemType & ");"

    try this

  12. #12
    cwwaicw311 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    75
    hi,

    the same problem still exist with your example. I have attached my database if u need to see what is the problem.

    Thank...

  13. #13
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Changed the code used recordset to insert data into the table. attaching the database for your reference.


    Private Sub Done_Click()
    Set rs = CurrentDb.OpenRecordset("TransactionTable")
    rs.AddNew
    rs!Date = Me.Date
    rs!Quantity = Me.Quantity
    rs!Remark = Me.Problem
    rs!PartID = Me.PartNumber
    rs!ItemID = Me.ItemType
    rs.Update
    rs.Close
    Set rs = Nothing
    End Sub

  14. #14
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    is it working now?????

  15. #15
    cwwaicw311 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    75
    yup... it is working now... Thank...

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

Similar Threads

  1. VBA Code for working with IE
    By smikkelsen in forum Programming
    Replies: 3
    Last Post: 04-15-2010, 01:05 AM
  2. Access 2003 code vs Access 2007 Code
    By ralphjramirez in forum Access
    Replies: 5
    Last Post: 11-23-2009, 12:33 PM
  3. Replies: 4
    Last Post: 05-12-2009, 01:50 PM
  4. Why isn't this working?
    By adiecidue in forum Queries
    Replies: 4
    Last Post: 04-27-2009, 10:29 AM
  5. Simple Nav Form Code Not Working
    By alsoto in forum Forms
    Replies: 10
    Last Post: 04-10-2009, 09:30 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