Results 1 to 13 of 13
  1. #1
    Lu.14-08-14 is offline Novice
    Windows 8 Access 2013 32bit
    Join Date
    Feb 2018
    Posts
    5

    How to transfer records from one listbox to another


    I to create a database for a small shop as coursework for my college. I have two Listboxes one with all of the stock of the business and another empty one, i want to select a record in the first record then click a button which would transfer the record to the empty Listbox. I have no idea how to do this.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    the listbox is based on a table, so you can run an append query to copy the record lsttBox2's table
    BUT dont forget to refresh the listbox2 to see the change:

    the following button click will run the query...
    Code:
    sub btnCopy_click()
       docmd.setwarnings false
       docmd.Openquery "qaCopy1ListBoxValue"     'this copies the value
       lstBox2.requery 
    
       docmd.setwarnings true
    end sub

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850

  4. #4
    Lu.14-08-14 is offline Novice
    Windows 8 Access 2013 32bit
    Join Date
    Feb 2018
    Posts
    5
    i followed every thing in the video however when i go to click on the button so that the records can transfer nothing happens, as in no error message appears nothing it transferred and at the bottom it still says i ran the query??? any help

  5. #5
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    Post 4 was moderated, I'm posting to trigger email notifications.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,706
    The method in the video works. Suggest you watch it carefully again and transfer the method to your listboxes and tables.
    If you're still stuck, post your DB here and someone will take a look.

  7. #7
    Lu.14-08-14 is offline Novice
    Windows 8 Access 2013 32bit
    Join Date
    Feb 2018
    Posts
    5
    its because in the video he has a field called "Deleted" which updates from 0 to 1 and thats how he transfers the records but i what i need to do is that im doing this for a corner shop so i want to simulate someone buying a product by them finding the product (record) they need and they would move it over to the second listbox then im yet to do another button which deducts the value from the quantity field in the table linked with the first listbox. so i dont know how to apply it to my DB

  8. #8
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,706
    but i what i need to do is that im doing this for a corner shop so i want to simulate someone buying a product by them finding the product (record) they need and they would move it over to the second listbox then im yet to do another button which deducts the value from the quantity field in the table linked with the first listbox.
    From the user's point of view:
    What happens if they want more than quantity one of a particular product? How do they do that? Multiple rows of same product on second listbox?
    What if they change their minds and want to move it back? Add back to stock on hand?
    What happens when the product quantity reaches zero? Does it disappear from the "Available" (first) listbox?

  9. #9
    Lu.14-08-14 is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2018
    Posts
    5
    What happens if they want more than quantity one of a particular product? - i want the product to show up in the first listbox if still available, so if i have 20 of one product and the user wants 5 then they would be able to add that product to the second listbox 5 times and it would still show in the first listbox because there is still 15 left, when the quantity reaches 0 then it will not show anymore in the first listbox.
    What if they change their minds and want to move it back? - i have also made a "remove" button which will send the product back to the first listbox

  10. #10
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,706
    OK. We need to know more. So far there is only a Products table with a quantity.
    Tell us more about the database functionality, and what you expect it to accomplish.

  11. #11
    Lu.14-08-14 is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2018
    Posts
    5
    i have sent you a private message

  12. #12
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,165
    Quote Originally Posted by ranman256 View Post
    the listbox is based on a table, so you can run an append query to copy the record lsttBox2's table
    BUT dont forget to refresh the listbox2 to see the change:

    the following button click will run the query...
    Code:
    sub btnCopy_click()
       docmd.setwarnings false
       docmd.Openquery "qaCopy1ListBoxValue"     'this copies the value
       lstBox2.requery 
    
       docmd.setwarnings true
    end sub
    Both of these methods use command buttons to call a saved query. What are the pros and cons of doing this vs hard coding the sql? EG
    Code:
    Sub btnCopy_click()
      Dim db As DAO.Database
      Set db = CurrentDb
      db.execute "INSERT INTO ..."
      db.close
      Set db = nothing
    
      lstBox2.requery
    End Sub

  13. #13
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    For a saved query, the pro is that it is saved and easy to edit. The con is that it is saved and easy to edit.

    For a query in code, the pro is that it is hard to edit. The con is that it is hard to edit.
    Building the action query in code allows you to tailor the SQL to exactly what you want. You can skip fields or add fields, depending on the data.
    In a saved query, it is what it is. Every time.


    In either case, I never use
    Code:
    docmd.setwarnings false
    docmd.Openquery "qaCopy1ListBoxValue
    I use "DoCmd.Execute (...), dBFailOnError"

    Using DoCmd.Openquery, Access first evaluates the SQL then passes it to the DBE. (DataBase Engine)
    Using the Execute method, the SQL is passed directly to the DBE. (Faster)




    My $0.02........

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

Similar Threads

  1. Transfer form listbox data to Report listbox.
    By onlylonely in forum Reports
    Replies: 6
    Last Post: 10-08-2017, 07:14 PM
  2. Replies: 3
    Last Post: 04-25-2017, 07:31 PM
  3. Transfer records from listbox 1 to listbox 2 gone wrong
    By Pommetje77 in forum Programming
    Replies: 6
    Last Post: 11-08-2016, 04:36 AM
  4. Replies: 7
    Last Post: 06-05-2012, 03:22 PM
  5. Replies: 1
    Last Post: 12-18-2011, 01:09 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