Linking Forms

  • Thread starter Thread starter Gloria
  • Start date Start date
G

Gloria

On my main form I want to add a button to open another form. When it opens
the subform I want the form to show only information about the specific
project shown in my main form. Any thoughts?
 
On my main form I want to add a button to open another form. When it opens
the subform I want the form to show only information about the specific
project shown in my main form. Any thoughts?

Why not actually use a Subform, in a subform control on your mainform? With
the proper master/child link field (the ProjectID or whatever it is) you'll
get the link automatically with no code.

Post back and explain why you need a separate form if you would like code to
do this - it's not hard but a lot more work than just a subform.
 
Thank you for responding, John.

My first form shows Proposal information. I have many proposals and all of
them do not turn into projects. I want to open the subform Projects by using
a button to enter the data for the project but I only want it to return
records for that Proposal. For example, Proposal No. P08003, I want to show
Project No. 08003 only.
 
Thank you for responding, John.

My first form shows Proposal information. I have many proposals and all of
them do not turn into projects. I want to open the subform Projects by using
a button to enter the data for the project but I only want it to return
records for that Proposal. For example, Proposal No. P08003, I want to show
Project No. 08003 only.

Then you'll need a Command button to open the form. It will need code to pull
the proposal number from the calling form, parse it into a project number (by
trimming off the first letter? is the Project number also a text field?) and
passing it to the called form. Untested air code:

Private Sub cmdOpenProject_Click()
Dim strProjno As String
strProjno = Mid(Me![ProposalNo], 2) ' extract 2nd-end of string
DoCmd.OpenForm "frmProjects", _
WhereCondition := "[ProjectNo] = '" & strProjNo & "'", _
OpenArgs := strProjNo
End Sub

The in the Project form's Open event put code like

Private Sub Form_Open(Cancel as Integer)
Me!ProjectNo.DefaultValue = Chr(34) & Me.OpenArgs & Chr(34)
End Sub

This will set the default value of ProjectNo to

"08003"

with the quotes, so new records will inherit the desired value.
 
Back
Top