This topic is locked

grabbing record from and autopopulate from another table

11/30/2006 12:45:34 PM
ASPRunnerPro General questions
S
SteveL author

i have two tables.. one called customers and one called units. They are related together by a master keyfield called customerID. I was wondering when I add in a units records how do i call the records from the customers table and have them autopopulate.

For example in customers I have fields such as

name,

address,

city,

state,

zip
in the units table i have the same fields

name

address

city

state

zip
how do I get these fields to autopopulate onload or after saving?
thanks
steve

J
Jane 12/1/2006

Steve,
you can do it using Before record added event.

Here is a sample code:

Function BeforeAdd(dict)

str = "select * from customers where CustomerID=" & dict("CustomerID")

Set rsTemp = server.CreateObject("ADODB.Recordset")

rsTemp.open str, dbConnection
dict("name") = rsTemp("name")

dict("address") = rsTemp("address")

dict("city") = rsTemp("city")

dict("state") = rsTemp("state")

dict("zip") = rsTemp("zip")
BeforeAdd = True

End Function