Re: Use Button To Call/Open 2nd Form & Pass Variable
- From: "maduckie123 via AccessMonster.com" <u39249@uwe>
- Date: Tue, 27 Nov 2007 14:32:50 GMT
Thanks for your help; it works now.
Dirk Goldgar wrote:
Thanks for taking the time to reply.[quoted text clipped - 6 lines]
presses the button on the main form. The query criteria will be a single,
distinct value having a single correlating record in the child table.
And yet, that decription seems to me to match the second scenario I
described. So maybe we're not quite on the same page with this. Let me
describe the scenario as I understand it:
1. User is viewing a form that displays one or more "parent" records. Each
parent record contains a field that relates to a record in a child table.
2. The user clicks a button to open another form that will display the child
record, if any, corresponding to the current parent record.
3. When the user is done with the child form, he simply closes it and
returns to the parent form.
If that's the scenario you're trying to implement, then this is exactly the
case I was referring to when I referred to "open[ing] a form filtered by a
particular value specified by the calling routine."
Suppose I have a table "tblParent" with fields "ParentID" (primary key) and
"ChildID", and a related table "tblChild", with field "ChildID" (primary
key). Suppose further that I have forms "frmParent" and "frmChild" based
respectively on these tables. On frmParent, we put a button named
"cmdOpenChild". The code for that button would be as simple as this:
'----- start of example code -----
Private Sub cmdOpen_Child_Click()
DoCmd.OpenForm "frmChild", _
WhereCondition:="ChildID = " & Me.ChildID
End Sub
'----- end of example code -----
That's assuming that the field ChildID is numeric; for example, an
autonumber in tblChild and a Long Integer in tblParent. If the field is a
text field, on the other hand, the where-condition must enclose it in
quotes, so the OpenForm line might look like this:
DoCmd.OpenForm "frmChild", _
WhereCondition:="ChildID = " & Chr(34) & Me.ChildID & Chr(34)
That will work for a text field, unless the text field contains the
double-quote character represented above by Chr(34). If that happens to be
the case, we have to do a teensy bit more work, but I won't bother posting
that until you tell me it's necessary.
The above seems very simple and straightforward to me, so maybe I've missed
something. And, of course, if this is not the scenario you had in mind,
then we may have to take a different approach.
--
Message posted via http://www.accessmonster.com
.
- References:
- Use Button To Call/Open 2nd Form & Pass Variable
- From: maduckie123
- Re: Use Button To Call/Open 2nd Form & Pass Variable
- From: Dirk Goldgar
- Re: Use Button To Call/Open 2nd Form & Pass Variable
- From: maduckie123
- Re: Use Button To Call/Open 2nd Form & Pass Variable
- From: Dirk Goldgar
- Use Button To Call/Open 2nd Form & Pass Variable
- Prev by Date: Can You Use SQL Max() Function Based on Variable From Form
- Next by Date: RE: Searching In Text Box
- Previous by thread: Re: Use Button To Call/Open 2nd Form & Pass Variable
- Next by thread: reset access menu back to original view
- Index(es):