Results 1 to 8 of 8
  1. #1
    cnstarz is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Posts
    31

    Cant display some records/records aren't in order

    I have two problems with my database:



    1) When you first load the "Personnel Security DB" form (first button on the switchboard), and you immediately hit the next/previous record buttons, all the records are in ascending order by last name, first name, middle initial. However, once you click on a name from the combo box and load a record, the order immediately changes to ascending order by SSAN (social security #). I can't figure out how to keep it in ascending order by last name, first name, middle initial.

    2) Some people in my database have the same last name. If you chose a record from the combo box that shares the same last name with someone else, the form will only display the record of the person with the lowest-value social security #. For instance, if you click on the "BAH, CAT" record, the "BAH, MEOW" record will be displayed instead because the social security number is of a smaller value (111-11-1111 vs 777-77-7777). Again, I have no idea how to remedy this.

    Any help is appreciated. Thanks!

  2. #2
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    I can't answer #2 (because I loathe dealing with listboxes - especially when they are using multiple columns) but for #1 the easiest way to do it is to add a query which returns everything from Main and then sorts the results the way you want (see screenshot). Set the query as the record source for the form instead of the table and it will keep its sorting.

  3. #3
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Question #2:
    Did you write the code or you get from other people?
    I find the code for click on the listbox as below:
    Code:
    Private Sub SearchNameList_Click()
        DoCmd.ShowAllRecords
        DoCmd.GoToControl ("Last")
        DoCmd.FindRecord Me!SearchNameList
    End Sub
    you find record with only the the last name as criteria, so it returns the first record with this last name.

    The solution is you should find the SSN instead of [last] (last name).

  4. #4
    cnstarz is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Posts
    31
    thanks slave138, i based the form off the query and kept everything alphabetized.

    weekend00, I found the code at another site. you're saying i should change it to:

    Code:
     
    Private Sub SearchNameList_Click()
        DoCmd.ShowAllRecords
        DoCmd.GoToControl ("SSAN")
        DoCmd.FindRecord Me!SearchNameList
    End Sub
    edit: i tried that but it actually broke the form. when you click on a record, the form won't update to display the record's data.

    edit2: fyi, the form I'm referring to is MainQueryForm.

    edit3: I really like the idea of the listbox changing as you type (like Google Suggestions), but if you know of a more efficient way of implementing this, please let me know.

  5. #5
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    you need to search for SSN, not lastname, so you need to change to(code in red):
    Code:
    Private Sub SearchNameList_Click()
        DoCmd.ShowAllRecords
        DoCmd.GoToControl ("SSAN")
        DoCmd.FindRecord Me!SearchNameList.column(3)
    End Sub

  6. #6
    cnstarz is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Posts
    31
    no bueno. i got this error when i added ".column(3)":

    "The FindRecord action requires a Find What argument."

  7. #7
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Why did I got the right thing after I added .column(3)?

  8. #8
    cnstarz is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Posts
    31
    i get the same error with the one you attached.

    "The FindRecord action requires a Find What argument." i'm on access 2007, i wonder if that's the difference.

    EDIT: GREAT SUCCESS! did some soul searching on google, and found this, http://dbaspot.com/forums/ms-access/...de-2007-a.html

    so, i changed the code to:

    Code:
    Private Sub SearchNameList_Click()
        Dim SearchNameListColumn3 As Variant
        SearchNameListColumn3 = Me!SearchNameList.Column(3)
        DoCmd.ShowAllRecords
        DoCmd.GoToControl ("SSAN")
        DoCmd.FindRecord SearchNameListColumn3
    End Sub
    for some reason, Access 2007 does not like "Me!SearchNameList.Column(3)". so, i definded "Me!SearchNameList.Column(3)" as "SearchNameListColumn3" and voila, all is good. i'm sure i'll be back for other questions cuz i'm learning as i'm building this. thanks for the help everyone!

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

Similar Threads

  1. Replies: 15
    Last Post: 10-01-2015, 10:06 AM
  2. How to use Rnd to order records?
    By Gdm in forum Queries
    Replies: 1
    Last Post: 05-26-2010, 09:01 PM
  3. Records change order
    By accessbeginner in forum Access
    Replies: 1
    Last Post: 03-18-2010, 06:38 PM
  4. Display all records
    By skwilliamson in forum Queries
    Replies: 3
    Last Post: 12-02-2009, 12:17 PM
  5. Display last five records only
    By premdasp in forum Queries
    Replies: 3
    Last Post: 11-18-2009, 11:53 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