Results 1 to 10 of 10
  1. #1
    jobrien4 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    20

    Selecting record in List Box and opening that record in another form

    I created a search form that searches for Customer Number, Part Number, and Revision Number. The results are displayed in a List Box.



    I want the user to be able to make a selection on the List Box and click an "Open Selected" button that launches that record in another form. How is this possible?

  2. #2
    dreday's Avatar
    dreday is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58
    The value of the listbox will be whatever they selected so when you click the "Open Selected" button you can either pass the value of the listbox as parameter to the new form if it's bound to a parametrized query or open the new form and set the filter option to filter for the record selected.

  3. #3
    jobrien4 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    20
    Ok but I have three values in each row of the list box. How do I pass along each value to the filter?

    This is what I'm trying right now:

    Dim SelectedPartNumber As String
    Dim SelectedRevisionNumber As String
    Dim SelectedCustomerNumber As Integer

    SelectedCustomerNumber = Me.SearchResults.Column(0)
    SelectedPartNumber = Me.SearchResults.Column(1)
    SelectedRevisionNumber = Me.SearchResults.Column(2)
    DoCmd.OpenForm "frm_PartDatabase", acNormal, , "Forms![frm_PartDatabase]![PartNumber]=SelectedPartNumber AND Forms![frm_PartDatabase]![RevisionNumber]=SelectedRevisionNumber AND Forms![frm_PartDatabase]![CustomerNumber]=SelectedCustomerNumber"


    When I debug, I'm getting the correct numbers as the variables, when it opens the new form, it's asking for the values as if it were a paramter query

  4. #4
    dreday's Avatar
    dreday is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58
    You need to assemble the string differently so all your variables can compute:

    DoCmd.OpenForm "frm_PartDatabase", acNormal, ,
    "Forms![frm_PartDatabase]![PartNumber]=" & SelectedPartNumber & " AND
    Forms![frm_PartDatabase]![RevisionNumber]=" & SelectedRevisionNumber & " AND
    Forms![frm_PartDatabase]![CustomerNumber]=" & SelectedCustomerNumber

    When they're stuck in the quotes you're actually passing whatever text is in the string instead of the values they represent. Try assembling the filter code in a string ahead of the open form action and check out the difference between the original filter and the one I provided

  5. #5
    jobrien4 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    20
    When I try this code, it opens the form with the header but nothing in the detail section

    If I remove the filter all together, it opens the form on the first record

  6. #6
    dreday's Avatar
    dreday is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58
    Try using just the field names without Forms![frm_PartDatabase] part and enclose the whole statement in parenthesis

  7. #7
    jobrien4 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    20
    It's now giving me the following error:

    Data type mismatch in criteria expression

    I checked and made sure PartNumber was set up as Text, RevisionNumber was set up as text, and CustomerNumber was set up as Long Interger

  8. #8
    dreday's Avatar
    dreday is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58
    Quote Originally Posted by jobrien4 View Post
    It's now giving me the following error:

    Data type mismatch in criteria expression

    I checked and made sure PartNumber was set up as Text, RevisionNumber was set up as text, and CustomerNumber was set up as Long Interger
    I bet you need extra quotes around the vars in the filter string to force the new form to treat them like text for PartNumber and RevisionNumber

    try this:
    DoCmd.OpenForm "frm_PartDatabase", acNormal, ,
    "[PartNumber]=""" & SelectedPartNumber & """ AND
    [RevisionNumber]=""" & SelectedRevisionNumber & """ AND
    [CustomerNumber]=" & SelectedCustomerNumber

    by putting an extra "" before and after the var it will insert a " into the actual string so it will come out looking like:

    [PartNumber] = "1234" AND [RevisionNumber] = "4556" AND [CustomerNumber] = 2343

    Since customer number is a Long we don't want to put quotes around it or we'll force another data mismatch

  9. #9
    jobrien4 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    20
    Thanks for you patience...that did it! Now I won't be trying to figure this out all weekend.

  10. #10
    dreday's Avatar
    dreday is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58
    Happy to help

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

Similar Threads

  1. Form Not Opening Correct Record
    By halfaguava in forum Forms
    Replies: 1
    Last Post: 06-09-2011, 07:00 PM
  2. Opening a form at a blank record
    By Remster in forum Forms
    Replies: 2
    Last Post: 09-14-2010, 07:46 AM
  3. Replies: 1
    Last Post: 08-27-2010, 05:16 AM
  4. Opening form to correct record. Bookmark?
    By stephenaa5 in forum Forms
    Replies: 11
    Last Post: 12-29-2009, 02:43 PM
  5. Replies: 4
    Last Post: 07-22-2009, 02:33 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