Results 1 to 4 of 4
  1. #1
    Lord-Vivec is offline Novice
    Windows 8 Access 2013 64bit
    Join Date
    Sep 2017
    Posts
    5

    Form to automatically link with record from which it was accessed

    Hi all,

    I have three main forms; Case List, Case Details, and Hearing Details. I can click on a court case in the Case List, which will open that case's Case Details form, and then I can click on New Hearing to add to a new hearing entry through the Hearing Details form. The Hearing Details form is based on a table which has [ID] primary key, and [CaseID] foreign key. The Case Details table's primary key is also [ID].

    The problem that I am having is that the user manually has to enter the CaseID foreign key (or select the case) in order to link the new hearing entry to the court case from which he just navigated. I would like to automate this; once you click on New Hearing, the CaseID should be automatically filled in based on the record from which the form was accessed. I found out that this is normally done using OpenArgs.

    I have the following set up, but it's currently not working:

    Case Details Form
    Private Sub cmdHearing_Click()
    DoCmd.OpenForm "Hearing Details", , , , acFormAdd, acDialog, Me.Parent![ID]
    End Sub

    Hearing Details Form
    Private Sub Form_BeforeUpdate(Cancel as Integer)
    Me![CaseID] = Me.OpenArgs
    End Sub



    Private Sub Form_Open(Cancel as Integer)
    Cancel = IsMissing(Me.OpenArgs) Or IsNull(Me.OpenArgs)
    If Cancel Then
    MsgBox "No Case Specified."
    End If
    End Sub

    The second part of the code is working (unless you navigate from the Case Details form, the Hearing Details form doesn't open), but clicking the button gives runtime error 2452; invalid reference to the Parent property.

    Thanks for helping out!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Is the case details form a subform? If not, it would just be

    Me.ID
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Lord-Vivec is offline Novice
    Windows 8 Access 2013 64bit
    Join Date
    Sep 2017
    Posts
    5
    This worked, thanks!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 8
    Last Post: 03-29-2017, 09:07 AM
  2. Replies: 4
    Last Post: 08-19-2016, 12:11 AM
  3. Replies: 1
    Last Post: 09-24-2014, 12:26 PM
  4. Replies: 3
    Last Post: 09-23-2012, 08:48 PM
  5. VBA to automatically re-link back end tables
    By bdaniel in forum Programming
    Replies: 2
    Last Post: 12-19-2011, 05:45 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