Form with SubForm popup

  • Thread starter Melindi via AccessMonster.com
  • Start date
M

Melindi via AccessMonster.com

I have a form that has a button to bring up a notes subform for that
record. The form and subform is based on the tracking number which is an
autonumber. But when I bring up the notes subform, the trackingno is blank
and I can't add new notes. It gives me a null error, because the tracking
number is null. How can I populate the subform with the trackingNo of the
record on the Main form???

On click of the button I have the following code:

Private Sub ViewNotes_Click()
On Error GoTo Err_ViewNotes_Click

DoCmd.OpenForm "sfrmNotes", WhereCondition:="TrackingNo=" & TrackingNo

Me.AllowEdits = True


Exit_ViewNotes_Click:
Exit Sub

Err_ViewNotes_Click:
MsgBox Err.Description
Resume Exit_ViewNotes_Click

End Sub
 
R

Rick Brandt

Melindi said:
I have a form that has a button to bring up a notes subform for that
record. The form and subform is based on the tracking number which
is an autonumber. But when I bring up the notes subform, the
trackingno is blank and I can't add new notes. It gives me a null
error, because the tracking number is null. How can I populate the
subform with the trackingNo of the record on the Main form???

First use the correct terminology. If you are opening it as a separate form
then it is not a subform. A subform is a form embedded within another using
a subform control. It is the embedded use of a subform control that allows
the automatic propogation of the linking field(s) between the parent form
and the child form. When you open the form separately (in a separate
window) then there is no automatic mechanism for creating the link or
keeping the second form synchroniized with the first.

You either have to use code to provide the default value for the linking
fields when you open the second form or use a defaultValue property like...

=Forms!NameOfFirstForm!NameOfLinkingField

The WHERE clause you are providing to the OpenForm method will filter the
second form so that any matching *existing* records will be displayed, but
that does nothing about any NEW records you might add.
 
P

PC Datasheet

What I do in a situation like this is to not make the subform a popup form
but leave it as a subform, set the left, top, width and height properties to
0, move the subform to an out-of-the-way place on the form and make it not
visible. Then the code for the button sets the left, top, width and height
properties appropriately so the subform is where I want it and then make it
visible. Doing it this way, the subform performs normally and the LinkChild
field is automatically entered.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top