Results 1 to 6 of 6
  1. #1
    roaftech is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Nov 2012
    Location
    Romania
    Posts
    65

    Display specified record in table


    I normally enter data using appropriate forms but from time to time I need to look at a particular record in the raw data (table). I use the following code behind a button in the calling form:
    Code:
    Private Sub OpenPersonsTable_Click()
    ' opens DataPersons table for general edit
        strTblName = "DataPersons"
        idFilter = Me.BID    'BID is a form control with the target identity, as used in the primary key of the table
        
        DoCmd.OpenTable strTblName, acViewNormal, acEdit
        DoCmd.FindRecord (idFilter)
    
    End Sub
    This is fine, except that the chosen record always shows up as the last record in the table window and I would prefer to be able to see the adjacent records as well. How can I use vba to scroll down and back up so that my chosen record is nearer to the vertical centre of the window?
    Note - Access 2003!

    TIA

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,446
    having found the record, you then need to move back up 5 or 6 records - the number determined by the number of records in the table, the size of the window and the number of rows currently being displayed in the window.

    You would normally do this in a form, I don't think you can do it in a table. The form could simply be a datasheet view of the table.

    if you have a subform to display the information, you can simply set the controlsource to 'Table.myTablename'. Or if you want the table to be viewed as a popup, create a blank popup form with just a subform control sized to suit, pass the table name as an openarg and some code in the form open event - subformcontrolname.controlsource="Table." & openargs

  3. #3
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    could you create a query which "focusses" on the 10 values either side of your chosen ID?
    Not sure it would work though

  4. #4
    roaftech is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Nov 2012
    Location
    Romania
    Posts
    65
    Thanks for the prompt responses - will explore further.

  5. #5
    roaftech is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Nov 2012
    Location
    Romania
    Posts
    65
    The forms approach would give more control but I found that adding these two lines of code to my original sub does what I want:
    Code:
        DoCmd.GoToRecord , , acNext, 5
        DoCmd.GoToRecord , , acPrevious, 5
    Now I might explore how to control the window size, but that is not a priority.

    Thanks for the ideas.

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,446
    glad you found a solution

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

Similar Threads

  1. Replies: 11
    Last Post: 11-04-2015, 12:41 PM
  2. Replies: 3
    Last Post: 10-28-2015, 12:38 PM
  3. Replies: 2
    Last Post: 11-07-2014, 02:53 PM
  4. Replies: 2
    Last Post: 12-21-2012, 01:57 PM
  5. Combo Boxes always display first record of table
    By LilMissAttack in forum Forms
    Replies: 4
    Last Post: 08-12-2011, 11:36 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