Results 1 to 10 of 10
  1. #1
    JakeMann41 is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2024
    Posts
    14

    Use a Button to Update A Table Field

    Hi Guys



    I have a form where I would like to press a button to update a field in a table

    On the form when an item is typed into the first text box, the second text box performs a dLookup and returns a location as per the table Stock and Location

    In the third text box I want to enter a new location.

    Then lastly a button that will update that location in the Stock and Locations table.

    The field to update in that table is called Location

    I am an amateur when it comes to access and queries but I presume a query needs to be writting to link the information in the third text box and the Stock and Location table.

    Any ideas who I can do this?

    A few pics attached
    Attached Thumbnails Attached Thumbnails form.PNG  

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,575
    I always start here
    That will likely lead to here

    From there is should be quite simple.
    I would probably change the button caption to Update Location as well.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    xps35's Avatar
    xps35 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jun 2022
    Location
    Schiedam, NL
    Posts
    300
    You are making it much to complicated. Just make a form bound to the Stock and Location table (better no spaces in names) and change the location there. The new location is changed directly in the table that way.
    Groeten,

    Peter

  4. #4
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,180
    Reality can be a bit more complicated. With stock movements not all items in location A are moved to location B, some may stay in location A or, if location B is smaller than location A, some may be moved to location B and some to location C.
    In existing warehouse software, you have a form to move stock items into locations where you have the possibility to distribute the items over several locations, the moved stock qty's are subtracted from the original location and added to the new locations, with a check on total quantities and a check that the max capacity of a location is not surpassed. We do it in a transaction within a procedure, if one of the checks fails, a rollback is done and the user is warned.

  5. #5
    JakeMann41 is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2024
    Posts
    14
    Thanks Peter, i can see that doing it that way adds a new line to the table - what I want to do is actually update the line that is already in the table. I would update the table itself by just going into it but I would like a neat process on a form to do that for me.

  6. #6
    xps35's Avatar
    xps35 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jun 2022
    Location
    Schiedam, NL
    Posts
    300
    Using a bound form you should be able to update an existing record directly by entering a new value into a field without adding a new record. I don't know what you did exactly.
    Groeten,

    Peter

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Whether you apply filter/search to bound form or run UPDATE action SQL, need criteria to locate existing record.

    For SQL in VBA, like:

    CurrentDb.Execute "UPDATE tablename SET fieldname=" & Me.textboxName & " WHERE ID=" & Me.anotherControlName

    Modify as appropriate if fields are text or date/time type and for however many parameters are needed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,180
    and don't forget to make the necessary checks, could be done in the beforeupdate event.
    Question: is it possible the items are split and reallocated on more than 1 location?

  9. #9
    JakeMann41 is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2024
    Posts
    14
    i think i've got it- if i change the filter lookup to never in the properties box that just changes the field on the table and doesn't input another line.

  10. #10
    ano is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2023
    Posts
    204
    i am not sure if you want change location name, which is what i not expect bec that is default in forms.
    i think u like to add/insert a new location ( not sure if it need to exist in table or not , but typing suggest its new in the table as well , bec else u select from available locations)

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

Similar Threads

  1. Replies: 3
    Last Post: 05-01-2019, 09:25 AM
  2. Cancel update of field if button clicked
    By Remster in forum Forms
    Replies: 10
    Last Post: 01-20-2019, 06:50 PM
  3. Replies: 2
    Last Post: 08-16-2016, 03:26 PM
  4. Replies: 12
    Last Post: 11-11-2014, 02:10 PM
  5. string on button to update field values
    By mike02 in forum Access
    Replies: 10
    Last Post: 07-10-2013, 12:41 PM

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