Results 1 to 7 of 7
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Add glossary entry > resort (2003)

    I have a small database with one table (tblGlossary) and a form that feeds off that table. Of course, the entries on the form are in alphabetical order. From time to time, I have to add a new term to the glossary, and the new item sits at the bottom of list until I close and reopen the form or the database. I'm sure there must be a way to force the form to refresh the sort order and place the new entry in its proper place...yes?

    By the way (FWIW), to add the new item, I simply use the "new" (*) icon on the navigation bar. I've considered adding a command button

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Add glossary entry > resort (2003)

    The single line

    Me.Requery

    in the On Click event procedure of the command button would sort the records on the primary key. You could also put this line in the After Insert event procedure of the form as a whole, but that would be rather disconcerting to the user - the form would jump back to the first record each time the user adds a record.

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Add glossary entry > resort (2003)

    <hr> Me.Requery...would sort the records on the primary key.<hr>
    Since this is a glossary, with records displaying in alphabetical order, resorting on the primary (numeric) key would produce undesireable results, wouldn't it? The form pulls from tblGlossary, which has three fields: ID (AutoNumber), Abbreviation (e.g., HCRT), and Definition (e.g., health care recruiter team). In the properties sheet for the form, I set the OrderBy property to tblGlossary.Abbreviation.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Add glossary entry > resort (2003)

    Just setting a sort order in the Properties window is not enough. I would create a query that sorts the glossary table on Abbreviation, and use that as record source of the form. Me.Requery will use the sort order of the query.

  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Add glossary entry > resort (2003)

    OK, I'm using a query as datasource. I've put a command button on the main form to add a new record. (I've chosen not to use a separate data-entry form...for now.) Here's the code generated in the VBE:

    <font face="Georgia">Private Sub cmdNewEntry_Click()
    On Error GoTo Err_cmdNewEntry_Click

    DoCmd.GoToRecord , , acNewRec

    Exit_cmdNewEntry_Click:
    Exit Sub

    Err_cmdNewEntry_Click:
    MsgBox Err.Description
    Resume Exit_cmdNewEntry_Click

    End Sub
    </font face=georgia>

    With this code, clicking the button takes me to a blank line to enter a new record. That's good, but it does not requery the list. I tried inserting the Me.Requery line in two different places in the code, but then the code didn't appear to work at all. Where to I insert that Me.Requery line?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Add glossary entry > resort (2003)

    This code will take the user to a new record. The user must then enter a new glossary entry. Until that has been done, it doesn't make sense to requery, so you can't do that in the On Click code for the cmdNewEntry button.

    One possibility is to put another button on the form that requeries it. The user must click this button to update the sort order.
    Another possibility is to requery the form in the After Insert event of the form; this has the advantage that the sort order will be updated automatically, without explicit action by the user, but it has the disadvantage that the form jumps to the first record as soon as the user has entered a new word and presses Tab or Enter; this is annoying if the user wants to add several entries in a row.

  7. #7
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Add glossary entry > resort (2003)

    I'll try the After Insert approach. I'm the guy who usually enters stuff for now, but that may soon change. Thanks again for your help, Hans! <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •