Results 1 to 9 of 9
  1. #1
    Pada is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2023
    Posts
    44

    Main Form passes ID value, but Details Form shows as a New Form

    In main form, I try to pass an ID value to the Details form using this line of code.



    DoCmd.OpenForm "frmMain", acNormal, , , , , ID.Value

    Then in my Details form, I have the following codes.

    Code:
    Private Sub Form_Load()
          Me.Filter = "[ID] = " & Me.OpenArgs
    
    End
    Code:
    Private Sub Form_Current()
    
    
        If NewRecord Then             'NewRecord is a built-in property of Form class.
            New_Record = True        'New_Record is a declared Global variable => it says New Record is True that is not right!
        Else
            New_Record = False
        End If

    However, when I click on the ID on the main form, although ID is passed to the Details form, it looks like the Details form doesn't receive it and it shows as a new blank form with a new ID that is an auto-number datatype in the
    table (record source) underline the Details Form.

    The weird thing is my friend has NO issue with passing the ID value to the Details form. I copied exactly her versions (frontend and backend) to my computer, but it ends up with faulty described above.
    I did compact and repair, deleted copies and did copy those versions again, and checked Reference, I still got the new blank form instead a Details form showing existing data.

    Please help! Tthank you!

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    You are setting a filter, but not setting the filter on?

    I would also use Me. for form controls/properties.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    If you really simply copied files and did not change anything, should work same.

    Could provide db for analysis. Follow instructions at bottom of my post.

    Could simply open detail form filtered by WHERE CONDITION argument of OpenForm instead of complicated Load and Current coding.
    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.

  4. #4
    Pada is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2023
    Posts
    44
    Quote Originally Posted by June7 View Post
    If you really simply copied files and did not change anything, should work same.

    Could provide db for analysis. Follow instructions at bottom of my post.

    Could simply open detail form filtered by WHERE CONDITION argument of OpenForm instead of complicated Load and Current coding.
    Hi June7, yes, I really simply copied files and that was it. That was why I said it's weird.

    I update the opening the Details form as following.
    The code below is from the ID_Click event (when I click on the ID control on the form, it takes me to the Details form)

    Code:
    DoCmd.OpenForm "frmDetails", acNormal, , , , , Me.ID.Value           'I added Me in the front of ID like Welshgasman said, but it still the same.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I wouldn't have expected that to make a difference.

    Maybe you should try my suggestion.
    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.

  6. #6
    Pada is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Aug 2023
    Posts
    44
    Hi Welshgasman and June7,

    I think I have found the issue. The culprit is the query's relationship (record source of the Details form). There is one field in the table that has no data. That is why the form pulls no record. I suspect my friend links her frontend with ANOTHER the backend (that has data), NOT on the backend version that I copied. Her fault!

    Thank you both of you trying to help. Appreciate it.

  7. #7
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    433
    what do you mean by "Detail form", is this a subform on your Main form?
    if it is you change the code of the "Detail form" Load Event to:
    Code:
    Private Sub Form_Load()
    Dim id As String
    id = Me.Parent.OpenArgs & ""
    If Len(id) Then
        Me.Filter = "ID = " & id
        Me.FilterOn = True
    End If

  8. #8
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    if it is you change the code of the "Detail form" Load Event to:
    Except subforms open/load before the main form, so the subform will not be able to reference anything having to do with the main form.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    433
    Quote Originally Posted by Micron View Post
    Except subforms open/load before the main form, so the subform will not be able to reference anything having to do with the main form.
    that is not entirely true.
    the code i posted is Tested on the subform on a Main form.

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

Similar Threads

  1. Replies: 4
    Last Post: 06-17-2021, 09:03 AM
  2. Replies: 2
    Last Post: 04-13-2020, 02:45 AM
  3. Replies: 7
    Last Post: 04-16-2018, 07:43 PM
  4. Replies: 1
    Last Post: 09-11-2012, 11:49 PM
  5. Two passes through report's control source?
    By GraeagleBill in forum Reports
    Replies: 2
    Last Post: 09-03-2012, 05:50 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