A Form that leads to a second Form

E

Emma

I have a button on my first form that opens up a second form which has a
button on it leading to a third form. I would like the 3rd form to gather the
client Name, Phone, ID from the first form. But when I do this I get the 1st
record in the database instead of the current client. So my question is how
do I pass that information along? I sort of remember using something like
[forms]![2nd form]![name] but not sure how this works in my query. Or do I
need to base my query on the 2nd form query?
 
K

ken

The best way to do this is to pass the values by means of the OpenArgs
mechanism; this allows for the calling form to be closed, or for the
called form to be opened in dialogue mode if necessary so that code
execution in the calling procedure will be suspended pending the
closure of the called form.

If the third form is a bound one which includes the client's ID in its
underlying table or query then you can filter the third form on
opening by means of the WhereCondtion argument of the OpenForm
method. So the code to open the second form would be:

DoCmd.OpenForm "[2nd Form]", _
OpenArgs:=Me.[ID]

The code to open the third form would be:

DoCmd.OpenForm "[3rd Form]", _
WhereCondition:="[ID] = " & Me.OpenArgs

Another possible scenario is that you are inserting a new row into the
table underlying the third form and wish it to reference the current
client. In this case you'd

Note that the DefaultValue property is a string expression, regardless
of the underlying data type of the column in question; hence the
delimiting quotes characters. In this scenario the name and phone
number should again be in computed controls as above, not stored in
columns in the underlying table as that introduces redundancy and
leaves the table open to inconsistent data being entered. In this
case you'd open the third form at a new record and pass the ID again
with:

DoCmd.OpenForm "[3nd Form]", _
DataMode:=acFormAdd, _
OpenArgs:=Me.OpenArgs

and in the third form's Open event procedure set the DefaultValue
property of the (bound) txtID control in the third form in its Open
event procedure with:

Me.txtID.DefaultValue = """" & Me.OpenArgs & """"

to show the client name and phone number in the third form either base
it on a query which includes the Clients table or use computed
controls with ControlSource properties of:

=DLookup("ClientName", "Clients", "ID = " & Me.txtID)

=DLookup("Phone", "Clients", "ID = " & Me.txtID)

or make the ID column's control a combo box which includes the name
and phone number in its RowSource e.g.

ControlSource: ID

RowSource: SELECT ID, Phone, ClientName FROM Clients ORDER BY
ClientName;

BoundColum: 1
ColumnCount: 2
ColumnWidths: 0cm;0cm;8cm

If your units of measurement are imperial rather than metric Access
will automatically convert the above to inches. The important thing
is that the first two dimensions of the ColumnWidths property are zero
to hide them.

Then include an unbound text box to show the phone number by
referencing the second column of the combo box with a ControlSource
property such as:

=cboID.Column(1)

The Column property is zero-based so Column(1) is the second column.

For more flexible ways of using the OpenArgs mechanism, involving the
passing of a value list or named arguments see:

http://community.netscape.com/n/pfx...yMessages&tsn=1&tid=24091&webtag=ws-msdevapps

Ken Sheridan
Stafford, England

I have a button on my first form that opens up a second form which has a
button on it leading to a third form. I would like the 3rd form to gather the
client Name, Phone, ID from the first form. But when I do this I get the 1st
record in the database instead of the current client. So my question is how
do I pass that information along? I sort of remember using something like
[forms]![2nd form]![name] but not sure how this works in my query. Or do I
need to base my query on the 2nd form query?
 
E

Emma

Sweet, I fixed my query and it works like a charm, Thanks

Steve said:
The first form needs to be open. It can be not visible. It needs to include
client Name, Phone and ID. The third form can gather the three fields from
the first form with:
MyClientName = Forms!NameOfFirstForm![Client Name]
ClientPhone = Forms!NameOfFirstForm!Phone
ClientID = Forms!NameOfFirstForm!ID

Steve
(e-mail address removed)




Emma said:
I have a button on my first form that opens up a second form which has a
button on it leading to a third form. I would like the 3rd form to gather
the
client Name, Phone, ID from the first form. But when I do this I get the
1st
record in the database instead of the current client. So my question is
how
do I pass that information along? I sort of remember using something like
[forms]![2nd form]![name] but not sure how this works in my query. Or do I
need to base my query on the 2nd form query?
 

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