Subforms

  • Thread starter Thread starter JB
  • Start date Start date
J

JB

Does anyone know how to create a subform that is opened
based on a command button? I am creating a database that
basically has a customer table and then tables for books,
seminars, contacts, etc. I want the option to click on a
command button to update one of the other tables. So
far, I can only get it to work if the subform is part of
the form.
 
A subform by definition *is* part of another form. I think you are asking
how to open a second form based on information in the first form. This can
be done fairly easily by using the WhereCondition parameter of the
Docmd.Openform statement:

stLinkCriteria = "Custid=" & Me!Custid
DoCmd.OpenForm "frmCustDetails", , , stLinkCriteria

The above code would open a form named "frmCustDetails" showing only records
where Custid is equal to the Custid in the current record of the form
executing this code.
 
What if the the custid is not yet in the other table and
you want to add it?
-----Original Message-----
A subform by definition *is* part of another form. I think you are asking
how to open a second form based on information in the first form. This can
be done fairly easily by using the WhereCondition parameter of the
Docmd.Openform statement:

stLinkCriteria = "Custid=" & Me!Custid
DoCmd.OpenForm "frmCustDetails", , , stLinkCriteria

The above code would open a form named "frmCustDetails" showing only records
where Custid is equal to the Custid in the current record of the form
executing this code.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Does anyone know how to create a subform that is opened
based on a command button? I am creating a database that
basically has a customer table and then tables for books,
seminars, contacts, etc. I want the option to click on a
command button to update one of the other tables. So
far, I can only get it to work if the subform is part of
the form.

.
 
Well, there are several ways you could do this. Is the form always going to
be used to add new records or is it used to display existing records when
they exist and only add new ones when no matching records exist?

You can always use the OpenArgs parameter to pass in a value to the second
form. The following will go to a new record if no matches are found:

Calling Form (form 1)
-------------------------------
DoCmd.OpenForm "frmCustDetail", , , "Custid=" & Me.custid, , , Me.Custid


Called Form (Form2)
--------------------------
Private Sub Form_Load()
If Len(Me.OpenArgs & "") > 0 Then
DoCmd.GoToRecord , , acNewRec
Me.Custid = Me.OpenArgs
End If

End Sub

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
What if the the custid is not yet in the other table and
you want to add it?
-----Original Message-----
A subform by definition *is* part of another form. I think you are asking
how to open a second form based on information in the first form. This
can be done fairly easily by using the WhereCondition parameter of the
Docmd.Openform statement:

stLinkCriteria = "Custid=" & Me!Custid
DoCmd.OpenForm "frmCustDetails", , , stLinkCriteria

The above code would open a form named "frmCustDetails" showing only
records where Custid is equal to the Custid in the current record of the form
executing this code.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Does anyone know how to create a subform that is opened
based on a command button? I am creating a database that
basically has a customer table and then tables for books,
seminars, contacts, etc. I want the option to click on a
command button to update one of the other tables. So
far, I can only get it to work if the subform is part of
the form.

.
 
If you only have a few possible different forms to open based on command
buttons you can try the following

Create the subforms you need and attache each to the main form with the
appropriate Child/Master fields,

Place them all in the same location on your main form (if you want) and
make them all invisible. They you can use your command buttons to make the
appropriate subforms forms visible or invisible

I will be watching the posts for a more elegant way to do this. But this
has worked for me.

Tom
 
Back
Top