Linking main and subform automatically

pablotx

Registered User.
Local time
Today, 05:28
Joined
Feb 20, 2003
Messages
79
Folks,

Ran into a problem today that I can't figure out. Should be an easy fix, but it has been years since I designed the database in question. Everything was working fine until yesterday and I can't find the solution.

Problem: Subform isn't opening with information from the main form unless I save main form information first. Attached is a very simple example. I want the subform to have the main form's information automatically.

Thanks in advance for the help.
 

Attachments

To begin with, you're not talking about a main form/subform, you're talking about opening a second form from your first form. A subform is a control within a main form that displays the contents of a second, usually related form.

You've already isolated the problem, the record on the first form has to be saved before its data can be passed to the second form, so save it! In the code for your button add the bold line:
Code:
Private Sub Command6_Click()
On Error GoTo Err_Command6_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

   [B]If Me.Dirty Then Me.Dirty = False[/B]

    stDocName = "subtab"

    stLinkCriteria = "[ID]=" & Me![ID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command6_Click:
    Exit Sub

Err_Command6_Click:
    MsgBox Err.Description
    Resume Exit_Command6_Click
    
End Sub
You code works as expected after that.
 
Last edited:
Thanks so much. It works like a charm.

What's funny is that I don't ever recall using that code back when the database was working properly. Thoughts?
 
My guess would be that you were doing something that was saving the record before trying to move to the second form; moving to another record, closing the first form, etc.
 

Users who are viewing this thread

Back
Top Bottom