Results 1 to 6 of 6
  1. #1
    SteveF is offline Generally AccessAble
    Windows XP Access 2010 32bit
    Join Date
    Nov 2010
    Location
    Fourth Corner
    Posts
    123

    Controlling Subform from Main Form


    OK, normally I'm the one answering questions here. This time, however, I've got a question.

    I'm working on a project to create a history of events for one of our clients. It's a many-to-many situation; each event has many people associated with it, and each person might be associated with more than one event. The project has been set up so that as events are added to the project, it checks to see if there are repeat people. If so, then the person and that event are only added to the cross-reference table; that person is not added to the Person table a second time.

    Since there's always room for variation in people's names (and how the data files that contain those names are structured), I have a manual-review form and subform built to check the new names against the existing data. This works, but could be improved. It's slow and mouse-intensive to select a specific existing record as a match for the new data.

    I'm thinking that things would run more smoothly if the mouse could be taken out of the processing loop, and only the keyboard used. Not a problem with only one form, but more complex with a form/subform.

    So, is there an easy way to control record navigation on a subform from the main form? Can I code a button on the main form to move to the next record on the subform? How about reading a unique value from the current record on the subform so that the match between the new person and the history data can be handled?

    TIA,
    Steve

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    Don't know if you want to call it easy, but yes, can control navigation of subform from main form. I use event of a combobox where users select a unique ID (a lab sample number) and VBA code finds the corresponding record in the subform.
    Code:
    Private Sub tbxLabNum_BeforeUpdate(Cancel As Integer)
    Dim rs As DAO.Recordset
    Me.Requery
    Set rs = Me.ctrSampleList.Form.RecordsetClone
    rs.FindFirst "LabNum='" & Me.tbxLABNUM & "'"
    If rs.NoMatch = True Then
        MsgBox "Invalid Lab Number", , "EntryError"
        Cancel = True
        Me.tbxLABNUM.SelStart = 6
    Else
        Me.ctrSampleList.Form.Bookmark = rs.Bookmark
    End If
    rs.Close
    End Sub
    I have coded custom Previous and Next buttons but not referencing subform. Is the subform in Datasheet view? Use Continuous or Single view and these buttons could be in header of the subform. Grabbing a value from current record of subform is simple: Me.subformcontainername!fieldname.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    SteveF is offline Generally AccessAble
    Windows XP Access 2010 32bit
    Join Date
    Nov 2010
    Location
    Fourth Corner
    Posts
    123
    OK, this does help. What I'm really after is to have some navigation buttons on the main form (First, Last, Next, Previous) that act on the subform. The subform is in Continuous Forms view; there's too much data being presented to the user for it all to fit on one line and I don't care for Datasheet View anyway.

    Navigation buttons that work on their own form (i.e. main form buttons that navigate main form records) are a piece of cake, obviously -- there are even Wizards that will build them:

    DoCmd.GoToRecord , , acNext

    I want to change that so the action takes place on the subform.

    Steve

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    It expect it can be done (never have) but why not use the Form Header section of the subform to hold the buttons that control that form's navigation?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Steve:

    To do navigation on the subform you can use:

    Code:
    Me.SubformControlNameHere.Form.Recordset.MoveNext

  6. #6
    SteveF is offline Generally AccessAble
    Windows XP Access 2010 32bit
    Join Date
    Nov 2010
    Location
    Fourth Corner
    Posts
    123
    Thanks, Bob -- that will do it.

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

Similar Threads

  1. Replies: 3
    Last Post: 04-04-2011, 02:45 PM
  2. Subform in a Tab Control on a Main form
    By jpkeller55 in forum Access
    Replies: 4
    Last Post: 01-08-2011, 12:31 PM
  3. opening a second form from main/subform
    By PJPCVP in forum Database Design
    Replies: 1
    Last Post: 10-29-2010, 09:50 PM
  4. Subform won't display in main form
    By Lynn in forum Forms
    Replies: 15
    Last Post: 03-22-2010, 10:17 AM
  5. Subform vs main form calculation
    By fadone in forum Forms
    Replies: 17
    Last Post: 12-21-2005, 07:27 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