p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

access thread: passing values to a second form, depending on the value of the first form


Message #1 by "Eric Van Camp" <eric@a...> on Mon, 3 Jun 2002 11:18:30 +0200
i have the following problem
Customers and telephones are linked tables, linked on customerID.
I want the user to fill in the customer's references and with a click on a
button to go to a popup window to fill in the details of the telephone (HIS
TELEPHONE).
I tried it using the wizard and a button with a macro giving the value of
the customerID, but ofcourse since he has not any telephones yet, the text
box with the customer's name is empty!!
How do i send this value to that popupwindow with the form of "telephones"
so that the field customerID is already filled in!
Eric Van Camp

Message #2 by "Gregory Serrano" <SerranoG@m...> on Mon, 3 Jun 2002 14:33:53
Eric,

<< i have the following problem Customers and telephones are linked 
tables, linked on customerID.  [snip]  How do i send this value to that 
popupwindow with the form of "telephones" so that the field customerID is 
already filled in! >>

Suppose customers the form is frmCustomers and the telephone pop-up form 
is frmTelephones.  Each has a field called txtCustomerName.  On 
frmTelephones "On Open" event include this statement.

   Me.txtCustomerName = Forms.frmCustomers.form.txtCustomerName

You also said you already passed the customer ID to the pop-up window.  
Therefore, you can also do this instead on the "on Open" event.

   Me.txtCustomerName = Dlookup("[strCustomerName]", "tblTelephones", _
                        "[strCustomerID] = '" & Me.txtCustomerID & "'")

Naming conventions:  The "str" (string) refers to text fields in the 
actual tables.  The "txt" refers to text boxes on the forms.  The "tbl" 
refers to a table.

Greg
Message #3 by "Gregory Serrano" <SerranoG@m...> on Mon, 3 Jun 2002 14:37:24
Correction!

<< You also said you already passed the customer ID to the pop-up window.  
Therefore, you can also do this instead on the "on Open" event.

    Me.txtCustomerName = Dlookup("[strCustomerName]", "tblTelephones", _
                         "[strCustomerID] = '" & Me.txtCustomerID & "'")
>>

Should be:

    Me.txtCustomerName = Dlookup("[strCustomerName]", "tblCustomers", _
                         "[strCustomerID] = '" & Me.txtCustomerID & "'")

The table to look up is tblCustomers, not tblTelephones.

Greg
Message #4 by "Eric Van Camp" <eric@a...> on Tue, 4 Jun 2002 08:43:50 +0200
another problem i have is that i need to open a new record..so the value i
get from the first form is perfectly transferred but as i do an " on open"
new record..the value is again lost...how do i retain the value of the
customer then?
txs
Eric

-----Original Message-----
From: Gregory Serrano [mailto:SerranoG@m...]
Sent: June 03, 2002 14:34
To: Access
Subject: [access] Re: passing values to a second form, depending on the
value of the first form


Eric,

<< i have the following problem Customers and telephones are linked
tables, linked on customerID.  [snip]  How do i send this value to that
popupwindow with the form of "telephones" so that the field customerID is
already filled in! >>

Suppose customers the form is frmCustomers and the telephone pop-up form
is frmTelephones.  Each has a field called txtCustomerName.  On
frmTelephones "On Open" event include this statement.

   Me.txtCustomerName = Forms.frmCustomers.form.txtCustomerName

You also said you already passed the customer ID to the pop-up window.
Therefore, you can also do this instead on the "on Open" event.

   Me.txtCustomerName = Dlookup("[strCustomerName]", "tblTelephones", _
                        "[strCustomerID] = '" & Me.txtCustomerID & "'")

Naming conventions:  The "str" (string) refers to text fields in the
actual tables.  The "txt" refers to text boxes on the forms.  The "tbl"
refers to a table.

Greg

Message #5 by "David Chapman" <luckychap@b...> on Tue, 4 Jun 2002 20:08:10 +0930
Pass the phone number as an argument, then access it on the on_open event.
Chech out Help - DoCmd.openform - the last parameter is arguments, which
could be the phone number.

David

-----Original Message-----
From: Gregory Serrano [mailto:SerranoG@m...]
Sent: Monday, June 03, 2002 2:34 PM
To: Access
Subject: [access] Re: passing values to a second form, depending on the
value of the first form


Eric,

<< i have the following problem Customers and telephones are linked
tables, linked on customerID.  [snip]  How do i send this value to that
popupwindow with the form of "telephones" so that the field customerID is
already filled in! >>

Suppose customers the form is frmCustomers and the telephone pop-up form
is frmTelephones.  Each has a field called txtCustomerName.  On
frmTelephones "On Open" event include this statement.

   Me.txtCustomerName = Forms.frmCustomers.form.txtCustomerName

You also said you already passed the customer ID to the pop-up window.
Therefore, you can also do this instead on the "on Open" event.

   Me.txtCustomerName = Dlookup("[strCustomerName]", "tblTelephones", _
                        "[strCustomerID] = '" & Me.txtCustomerID & "'")

Naming conventions:  The "str" (string) refers to text fields in the
actual tables.  The "txt" refers to text boxes on the forms.  The "tbl"
refers to a table.

Greg

Message #6 by "Amy Wyatt" <amyw@c...> on Wed, 5 Jun 2002 13:32:35
You could also set up a Global variable that will stay active until it 
reset or the database is closed. You do this in the General Declarations 
section with

Public strCustNum as String (for example)

Amy

> another problem i have is that i need to open a new record..so the value 
i
get from the first form is perfectly transferred but as i do an " on open"
new record..the value is again lost...how do i retain the value of the
customer then?
txs
Eric

-----Original Message-----
From: Gregory Serrano [mailto:SerranoG@m...]
Sent: June 03, 2002 14:34
To: Access
Subject: [access] Re: passing values to a second form, depending on the
value of the first form


Eric,

<< i have the following problem Customers and telephones are linked
tables, linked on customerID.  [snip]  How do i send this value to that
popupwindow with the form of "telephones" so that the field customerID is
already filled in! >>

Suppose customers the form is frmCustomers and the telephone pop-up form
is frmTelephones.  Each has a field called txtCustomerName.  On
frmTelephones "On Open" event include this statement.

   Me.txtCustomerName = Forms.frmCustomers.form.txtCustomerName

You also said you already passed the customer ID to the pop-up window.
Therefore, you can also do this instead on the "on Open" event.

   Me.txtCustomerName = Dlookup("[strCustomerName]", "tblTelephones", _
                        "[strCustomerID] = '" & Me.txtCustomerID & "'")

Naming conventions:  The "str" (string) refers to text fields in the
actual tables.  The "txt" refers to text boxes on the forms.  The "tbl"
refers to a table.

Greg

Message #7 by "Leo Scott" <leoscott@c...> on Wed, 5 Jun 2002 00:21:07 -0700
I would suggest using the openargs:= parameter in the code that opens the
popup form and placing the CustomerID in that variable.

DoCmd.OpenForm FormName:="Something", OpenArgs:="CustomerID"

then in the popup form you always have

Me.OpenArgs

to retrieve the CustomerID value of the calling form.  This, along with a
recordset gets you to any of the data associated with the CustomerID of the
calling form even if you move to a different CustomerID on the popup form.
It also preserves encapsulation in the popup form, which is really just a
class/object, where using a global variable would not.

|-----Original Message-----
|From: Amy Wyatt [mailto:amyw@c...]
|Sent: Wednesday, June 05, 2002 1:33 PM
|To: Access
|Subject: [access] Re: passing values to a second form, depending on the
|value of the first form
|
|
|You could also set up a Global variable that will stay active until it
|reset or the database is closed. You do this in the General Declarations
|section with
|
|Public strCustNum as String (for example)
|
|Amy
|
|> another problem i have is that i need to open a new record..so the value
|i
|get from the first form is perfectly transferred but as i do an " on open"
|new record..the value is again lost...how do i retain the value of the
|customer then?
|txs
|Eric
|
|-----Original Message-----
|From: Gregory Serrano [mailto:SerranoG@m...]
|Sent: June 03, 2002 14:34
|To: Access
|Subject: [access] Re: passing values to a second form, depending on the
|value of the first form
|
|
|Eric,
|
|<< i have the following problem Customers and telephones are linked
|tables, linked on customerID.  [snip]  How do i send this value to that
|popupwindow with the form of "telephones" so that the field customerID is
|already filled in! >>
|
|Suppose customers the form is frmCustomers and the telephone pop-up form
|is frmTelephones.  Each has a field called txtCustomerName.  On
|frmTelephones "On Open" event include this statement.
|
|   Me.txtCustomerName = Forms.frmCustomers.form.txtCustomerName
|
|You also said you already passed the customer ID to the pop-up window.
|Therefore, you can also do this instead on the "on Open" event.
|
|   Me.txtCustomerName = Dlookup("[strCustomerName]", "tblTelephones", _
|                        "[strCustomerID] = '" & Me.txtCustomerID & "'")
|
|Naming conventions:  The "str" (string) refers to text fields in the
|actual tables.  The "txt" refers to text boxes on the forms.  The "tbl"
|refers to a table.
|
|Greg
|


  Return to Index