Link form to subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello experts,
This is going to be tricky to explain but here goes...
I have a subform sbfrm_PDiff and the data source is tbl_PDiff.
Here are some facts about sbfrm_PDiff:
1 - it only shows a few of the fields from tbl_PDiff
2 - it is in datasheet view on parent form
Now here is my problem:
I wanted to add a button on each record of the subform to show three of the
fields from tbl_PDiff that are not on sbfrm_PDiff in a new frm_PDiffMemo (the
reason for this is because they are memo fields and the rest are currency and
text fields that are showing on sbfrm_PDiff).
I'm having trouble bringing up frm_PDiffMemo from sbfrm_PDiff and have it
link correctly so that I can populate the memo fields for that record.
Does this make sense? is there a better way to do this?
I need some help please!
 
Subforms are not part of the Forms collection, which only includes open main
forms so you can't refer to them directly in the usual way. You can refer to
it via its Parent form. This includes a control which houses the subform and
the Form property of this control returns a reference to the subform.
However in your case, as you are putting the button on the detail section of
the subform itself you can simply refer to the to the subform's current
record's primary key to provide a criterion for opening the second form, so
the code for your button's Click event procedure would go like this:

Dim strCriteria As String

strCiteria = "MyID = " & Me.MyID

DoCmd.OpenForm " frm_PDiffMemo", WhereCondition:=strCriteria

This assumes that MyID is the primary key of the subform's underlying
recordset and is a number data type, and that form frm_PDiffMemo includes
MyID in its underlying recordset, which it will of course if its RecordSource
is the table. If the primary key were a string it would need to be wrapped
in quotes like so:

strCriteria = "MyID = """ & Me.MyID & """"

Before you can add the button to the form, however, you'll need to change it
from a datasheet view to continuous form view, putting the field names in the
form header and having the detail section just one line deep, with the text
boxes in a horizontal line. Personally I always use continuous forms rather
than datasheets; you have more control over their appearance and can achieve
a more visually consistent style to your application.
 
Back
Top