Results 1 to 13 of 13
  1. #1
    rcerda is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    18

    Selecting a record from a list


    I have a form with a list of records, and I want to be able to select one record and display it in a new form. I have tried a few things, but unfortunately does not give me the results I want.

    The form displays the bills for a customer, and I want to be able to select bills individually to check them out.

    Thank you

  2. #2
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Add code to the listbox after update event
    The bound column of your listbox is normally an ID field from a table or query
    So you use that to filter your form to that ID

    Your code should be similar to this - but using your own field/table/form names

    Code:
    Private Sub MyListBox_AfterUpdate()
    
       use next line 'if ID field is a number
       DoCmd.OpenForm "MyFormName", , ,"ID = " & Me.MyListBox  
    
      'if its a text field then use text delimiters
       DoCmd.OpenForm "MyFormName", , ,"ID = '" & Me.MyListBox & "'"
    
    End Sub

  3. #3
    rcerda is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    18
    Quote Originally Posted by rcerda View Post
    I have a form with a list of records, and I want to be able to select one record and display it in a new form. I have tried a few things, but unfortunately does not give me the results I want.

    The form displays the bills for a customer, and I want to be able to select bills individually to check them out.

    Thank you
    Thank you for your answer. I am a little confused. I tried the code replacing using the field I click on to select the record but still gives me an error. Is your code designed to work with a combo box, because I am trying to select a record from a list by clicking on the particular record.

  4. #4
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    No - its for a listbox (though it would also work for a combo)

    Not sure what this means:
    I tried the code replacing using the field I click on to select the record but still gives me an error.
    Please post the code you used in full including procedure name
    What error did you get? give a screenshot
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  5. #5
    rcerda is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    18
    Quote Originally Posted by ridders52 View Post
    Add code to the listbox after update event
    The bound column of your listbox is normally an ID field from a table or query
    So you use that to filter your form to that ID

    Your code should be similar to this - but using your own field/table/form names

    Code:
    Private Sub MyListBox_AfterUpdate()
    
       use next line 'if ID field is a number
       DoCmd.OpenForm "MyFormName", , ,"ID = " & Me.MyListBox  
    
      'if its a text field then use text delimiters
       DoCmd.OpenForm "MyFormName", , ,"ID = '" & Me.MyListBox & "'"
    
    End Sub
    The code I used:

    Private Sub Detalle_Click()
    DoCmd.OpenForm "frmrecepcionesrecord", , , "Guia de Recepción = " & Me.Guía_de_Recepción
    End Sub
    Attached Thumbnails Attached Thumbnails Consulta.jpg  

  6. #6
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    You haven't followed my code at all

    I said to use the after update event of your listbox as shown in my example code - not the click event
    Is Detaile the name of your listbox (or the Detail section on your form)

    Is Guia de Recepcion the bound field in your listbox & is it a number field?

    The right side of the equals sign needs to reference your listbox (as I showed) so it uses the selected value

    NOTE:
    No need to quote all my post unless you are referring to it.
    No need to show a screenshot of the code - the code itself is fine

    I did ask for a screenshot of the error that occurred
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  7. #7
    rcerda is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    18
    idders52
    You haven't followed my code at all

    I said to use the after update event of your listbox as shown in my example code - not the click event
    Is Detaile the name of your listbox (or the Detail section on your form)

    R- I used the after update you sent but it didn't do anything

    Is Guia de Recepcion the bound field in your listbox & is it a number field?

    R- Yes, so I have a form which l did from a query that lists all of the Clients and their bills. Then I used that form as a subform, where it pulls the bill for everyclient. which is working fine, exept that whenever I have a client with multiple bills and I want to select one to look at it in detail on a columnar form it does not work. What I did last which is almost working, since it at least opened the form is Onclick but it gives me no record in it.

    The right side of the equals sign needs to reference your listbox (as I showed) so it uses the selected value
    R- which I did I listed the list box, which I suppose is the form I created with the list of clients and their bills ??


    NOTE:
    No need to quote all my post unless you are referring to it.
    No need to show a screenshot of the code - the code itself is fine

    I did ask for a screenshot of the error that occurred

  8. #8
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    You've told me lots of things but still failed to answer most of what I asked
    1. What is the name of your listbox?
    2. What is the name of the bound field in the listbox? Is it a text field or a number field?
    3. What error occurred? Can you upload a screenshot?

    I know the code I supplied will work if you follow the exact instructions I gave
    I also know the code you posted will not work
    BUT unless you answer ALL the questions I've asked, I can't help you further
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  9. #9
    rcerda is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    18
    You've told me lots of things but still failed to answer most of what I asked
    1. What is the name of your listbox?
    R- frmrecepciones

    2. What is the name of the bound field in the listbox? Is it a text field or a number field?
    R- Guia de Recepción

    3. What error occurred? Can you upload a screenshot?
    R- Error 2501 de OpenForm function was cancelled


  10. #10
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Thank you. Some progress but not enough to write the code for you
    Extra comments in RED

    Quote Originally Posted by rcerda View Post

    1. What is the name of your listbox?
    R- frmrecepciones
    - I thought that was the name of the form you want to open
    Seems odd to name a listbox starting with frm...

    In that case, what is the name of the form you want to open?
    And what was 'Detaile'?

    2. What is the name of the bound field in the listbox? Is it a text field or a number field?
    R- Guia de Recepción
    - text or number datatype?
    3. What error occurred? Can you upload a screenshot?
    R- Error 2501 de OpenForm function was cancelled
    - OK thank you

    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  11. #11
    rcerda is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    18
    1. What is the name of your listbox?
    R- frmrecepciones
    - I thought that was the name of the form you want to open
    Seems odd to name a listbox starting with frm...
    R- I think I know what the problem is. I am not using a listbox, I am using form which lists all of the records for that customer (which includes the bill details). So what I do is click on the Guia de Recepción field and it should bring that whole record in a new form to look at it in detail

    In that case, what is the name of the form you want to open?
    And what was 'Detaile'?
    R - the form to open is called frmrecepcionesrecord, which has a columnar form that displays the fields of the record selected.

    2. What is the name of the bound field in the listbox? Is it a text field or a number field?
    R- Guia de Recepción
    - text or number datatype? text, so I used the text delimeters

    3. What error occurred? Can you upload a screenshot?
    R- Error 2501 de OpenForm function was cancelled
    - OK thank you

  12. #12
    rcerda is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    18
    I am almost there with a Macro, but it loads the wrong record, I even select the Client ID and the Guía de Recepción to make sure that is loads the correct record, but it loads a different Client ID and Guia de Recepción, and the syntax of the macro is correct. I think Access has its peculiarities if I might say so.

  13. #13
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    OK I'm going to leave you to it as I've asked several questions repeatedly without success.
    Good luck solving it
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

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

Similar Threads

  1. Selecting Different Value from Select List
    By emhill57 in forum Access
    Replies: 5
    Last Post: 09-20-2017, 02:47 PM
  2. Data not filtered after selecting item in the list box
    By sukhjinder in forum Programming
    Replies: 4
    Last Post: 08-15-2017, 09:40 AM
  3. Selecting Just One List Box
    By Khatru in forum Forms
    Replies: 1
    Last Post: 03-30-2015, 12:01 PM
  4. Replies: 9
    Last Post: 09-16-2011, 03:52 PM
  5. Replies: 1
    Last Post: 11-11-2006, 08:23 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