Results 1 to 11 of 11
  1. #1
    ZakariaAadel is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2020
    Posts
    6

    How to select record by using VBA

    Hey everyone,


    i have some problem, i want to select some information by using vba because i want this logic when the user click on 'Ajouter au panier' the system have to select the product and add it on the list Box of 'Panier'
    this is the interface of the form_dialog to understand me

    logically this what I want like you sad "add a product to a list box when you press a button" and why I want this because if you see in the form I have already selected the product in the drop-down list (combo box) and after when i click on the button i want to add it on the list box automatically by VBA code if you know it this is like a concept of shopping cart and this what the action i want it after clicking on the button i hope you understand me

    Please can you give me the solution what is the code i can use it here ?




  2. #2
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    What is the source of the list box? You would either need to use an append query to add a record to a (temporary) table that acts as the list box row source or an update query to "check" (=True) a Yes/No field in a table (such as a IsSelected field).

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    You may get some ideas from the Similar Threads at the bottom of the page. If not, then readers will need to see some of your code behind your form and controls as Vlad has mentiooned.

  4. #4
    ZakariaAadel is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2020
    Posts
    6
    Thanks for you reply now i have another problem when i select the product the information relied on product insert automatically but the picture attached not insert this the problem display


    this is the code VBA in back :

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    What is the code behind your Ajouter au panier button?
    Can you post a copy of your database(zip format)?

  6. #6
    ZakariaAadel is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2020
    Posts
    6
    the problem is on the combo box this is the code behind the combo box
    Private Sub txtListPrdct_AfterUpdate()
    Dim db As Database
    Dim rs As Recordset
    Set db = CurrentDb
    Set rs = db.OpenRecordset("SELECT * FROM TB_Article WHERE IDProduit=" & Me.txtListPrdct.Value, dbOpenDynaset)
    If Not rs.EOF Then rs.MoveFirst
    Me.txtNatrPrd = rs("nature_produit")
    Me.txtPrxVente = rs("prix_vente")
    Photo_produit.CurrentAttachment = rs("Pic_Prod")
    Me.txtQtedemande.SetFocus
    rs.Close
    Set rs = Nothing
    db.Close
    Set db = Nothing
    End Sub

    because the button Ajouter au panier it's for adding the product after selected these last these problem it's when i selected the product on combo box 'listPrdct'

    yes of course i send you my frontend application

  7. #7
    ZakariaAadel is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2020
    Posts
    6
    if you want to download my application this is the link
    https://mega.nz/file/dIM2SbKB#Fp1kvx...adCayLWZ_BYzFk

  8. #8
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    How do we arrive at the Form that contains the List?
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  9. #9
    ZakariaAadel is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2020
    Posts
    6
    I solved the problem myself,
    Thanks to all members for helping

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

  11. #11
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Code:
       Me.txtQtedemande.SetFocus
        rs.Close
        Set rs = Nothing
        db.Close
        Set db = Nothing
    End Sub
    The rule I was taught eons ago is:
    If you create it (an object), destroy it. (you create it by using the "SET" keyword)
    If you open it (an object), close it. (you open a recordset using the "OpenRecordset" keyword)

    Since you didn't (and don't) OPEN "db", you shouldn't close it. Think about it. You have to open a recordset to see the records, but you never open the "database".



    BTW, when declaring the variables, you should have
    Code:
    Dim db As DAO.Database
    Dim rs As DAO.Recordset

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

Similar Threads

  1. Replies: 9
    Last Post: 04-09-2020, 04:15 PM
  2. Replies: 32
    Last Post: 05-23-2013, 04:16 PM
  3. Replies: 3
    Last Post: 02-06-2013, 07:23 PM
  4. Replies: 2
    Last Post: 12-21-2012, 01:57 PM
  5. Replies: 3
    Last Post: 08-26-2012, 10:04 PM

Tags for this Thread

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