Results 1 to 3 of 3
  1. #1
    geo47 is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2022
    Posts
    1

    linking forms

    'Form fmLog2File is paired with fmLogFile by code as follows:

    Private Sub Form_Current()
    Dim Form As Form



    Set Form = Forms("fmLogFile")
    Form.Filter = "logID = " & Me!logID.Value & ""
    Form.FilterOn = True
    End Sub

    'The same form fmLog2File is paired with fmLogOp by similar code as follows

    Private Sub Form_Current()
    Dim Form As Form

    Set Form = Forms("fmLogOp")
    Form.Filter = "logID = " & Me!logID.Value & ""
    Form.FilterOn = True
    End Sub

    'My idea is to avoid 2 pairs of forms and 2 pieces of similar code, e.g. one piece of code which will link fmLog2File with 2 other forms simultaneously. Can you help me out with this please?

  2. #2
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,821
    Hi
    The normal process is to link Forms using the PK from table 1 and Link it to the FK in the related Table2 using Link Parent/Link Child values

    The FK in the related table would then auto-populate when adding new records.

  3. #3
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I thought the question was about how to avoid repetitive code so that's how I'll approach it. To avoid that you can create a function or sub in a standard module and call it from the form event, kind of like (untested)
    Code:
    Private Sub Form_Current()
    
    SetFilter(Me.Name)
    
    End Sub
    
    Function SetFilter(frmName As String)
    With Forms(frmName)
      .Filter = "logID = " & Forms(frnName).logID
      .FilterOn = True
    End With
    
    End Sub
    Advise not to use reserved words for objects (e.g. Form). The called code above could just as easily be a Sub instead if there is no need to return anything to the code that calls it. You could also add the filter as a parameter, but I didn't because they're the same in each case.

    EDIT - in case I missed the intent of the question, maybe you should be using a subform and setting the linked Child and Master properties?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Linking two forms
    By boydwspoon in forum Forms
    Replies: 1
    Last Post: 10-11-2012, 11:59 AM
  2. Linking Forms
    By ChipVerdi55 in forum Forms
    Replies: 10
    Last Post: 06-26-2012, 02:49 AM
  3. Linking two forms
    By JeffG3209 in forum Forms
    Replies: 3
    Last Post: 05-09-2011, 12:26 PM
  4. Linking forms
    By warrigal in forum Database Design
    Replies: 2
    Last Post: 04-07-2011, 05:12 PM
  5. Linking Forms
    By dalton in forum Forms
    Replies: 1
    Last Post: 05-30-2010, 11:23 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