Results 1 to 11 of 11
  1. #1
    Business is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2016
    Posts
    78

    update table from a form using a button

    Hi;


    I m struggling for days now because i can not code properly the UPDATE button to update the stock quantity of an item selected. The result that i get update all the quantity in the stock level. Those are the codes i m using


    Dim strSQL As String
    Dim rst As DAO.Recordset
    strSQL = "UPDATE [Stock] Set [produitQuantite] = " & me.txtRest "
    CurrentProject.Connection.Execute strSQL

    In this case productQuantity represent the stock level and txtrest the substraction between the productQuantity and the quantity issued. the problem is that the result update all the items quantity in the table.

    can anyone help pleqse

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Try
    Code:
    Dim strSQL As String
    Dim rst As DAO.Recordset
    strSQL = "UPDATE Stock Set [produitQuantite] = " & me.txtRest 
    CurrentdB.Execute strSQL, dbfailonerror
    You were mixing DAO and ADO syntax.


    Is the field name really [produitQuantite]?? (maybe [productQuantity]?)

  3. #3
    Business is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2016
    Posts
    78
    Thanks Steve yes the field name is produitQuantite. the problem that i m facing is that it s update all the quantity in the stock table. or it has to update just the one selected.

  4. #4
    nhorton79 is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Apr 2015
    Posts
    34
    If you only want it to update a particular record you will need to include a WHERE clause...


    Sent from my iPhone using Tapatalk

  5. #5
    Business is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2016
    Posts
    78
    how do i go about it; i m still a novice in this. Could you help with this same close. where should be included in which way
    Regards

  6. #6
    nhorton79 is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Apr 2015
    Posts
    34
    You could try:

    Code:
    Dim strSQL As String
    Dim rst As DAO.Recordset
    strSQL = "UPDATE Stock SET [produitQuantite] = " & me.txtRest & " WHERE [StockID] = " & me.txtStockID
    CurrentdB.Execute strSQL, dbfailonerror
    This will depend on what the primary key for the stock is, and also on how this is tracked on your (form?).

    So you would replace the StockID with your primary key and me.txtStockID with the textbox name you are using on the form.

    Make a copy of your database before trying....

    Hope this helps. Let me know how it goes...

    Nick

  7. #7
    Business is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2016
    Posts
    78
    Thanks Nick but i still get an error message. on my form i do not track the productId but the product name that display in a combo box with the item name and quantity in stock. can i have an email adresse to send out the application for you to have a better look at the problem

  8. #8
    nhorton79 is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Apr 2015
    Posts
    34
    Yeah, might be best if look directly at the database. I'll message you my email address. Send it through - although it may be a while as it's bedtime here where I live but could look at tomorrow for you.


    Sent from my iPhone using Tapatalk

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    What Nick said.... Need a "Where" clause.

    You could post the dB here so a lot more people could look at it..........I'm just saying.....

  10. #10
    nhorton79 is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Apr 2015
    Posts
    34
    Okay...I've had a look at your database and have got the UPDATE function working and updating only the product line in stock referenced in the form.
    This is done using a WHERE clause in your UPDATE statement.
    I've sent this back to you via email - Hope this helps.

    However, I believe you are going about this in the wrong way....
    You shouldn't really be storing the stock on hand amount in your database directly on the product table.

    Have a look at this page by Allen Brown which shows in great detail exactly how to manage stock and the necessary stocktakes.
    http://allenbrowne.com/appinventory.html

    Allen Brown has some great articles on his site about designing databases plus other functions and tips for novices.

    Nick

  11. #11
    Business is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2016
    Posts
    78
    Thanks guys i have fixed the problem. Nick i ll be in touch if more troubles comes alongs.

    Regards

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

Similar Threads

  1. Replies: 2
    Last Post: 04-02-2015, 08:04 PM
  2. Replies: 12
    Last Post: 11-11-2014, 02:10 PM
  3. Replies: 1
    Last Post: 12-03-2012, 02:50 PM
  4. Replies: 7
    Last Post: 09-21-2012, 11:09 AM
  5. Replies: 1
    Last Post: 06-15-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