Getting a Customer ID from one form to the next ??

  • Thread starter Thread starter Don Garry
  • Start date Start date
D

Don Garry

I'm struggling trying to get a CustomerID from one form to another ???

Here's my situation. I have a form A which when open allows me to search for
a specific customer. Once I've found the correct customer (e.g. let's say
record #8 out of 20) I want to pass the associated customer ID back to
another open form B.

Everything works fine as long as I don't move from the first record in Form
A. If I do move from the first record I get the customer ID for the first
record being passed back to form B rather than record #8.

I've looked at the help menus around bookmarks but just get a little more
confused.

Any assistance would sure be appreciated.
 
Hi Don,

To link the two forms so that form B always displays the customer selected
on form A, use the command button wizard to generate the code - it asks you
if you want to link the two forms by a unique id e.g.:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "formA"

stLinkCriteria = "[CustomerID]=" & Me![CustomerID]
DoCmd.OpenForm stDocName, , , stLinkCriteria


If you than want to insert data into form B, you need to put the following
in the before insert event of form B:

Me!CustomerID = Forms!formA!CustomerID

Make sure that form A cannot be closed whilst form B is open, otherwaise the
above will fall over.

However, if form B is already open when you select your record on form A,
base you recordset for form B on a query which gets selects the customer ID
from form A, then after selecting the record in form A, requery form B.

If you need an example of this, reply back and I'll send you a small example
DB.

Paul
 
Hi Paul,
Can you send an example, please.
Thanks a lot.

Paul Doree said:
Hi Don,

To link the two forms so that form B always displays the customer selected
on form A, use the command button wizard to generate the code - it asks you
if you want to link the two forms by a unique id e.g.:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "formA"

stLinkCriteria = "[CustomerID]=" & Me![CustomerID]
DoCmd.OpenForm stDocName, , , stLinkCriteria


If you than want to insert data into form B, you need to put the following
in the before insert event of form B:

Me!CustomerID = Forms!formA!CustomerID

Make sure that form A cannot be closed whilst form B is open, otherwaise the
above will fall over.

However, if form B is already open when you select your record on form A,
base you recordset for form B on a query which gets selects the customer ID
from form A, then after selecting the record in form A, requery form B.

If you need an example of this, reply back and I'll send you a small example
DB.

Paul

Don Garry said:
I'm struggling trying to get a CustomerID from one form to another ???

Here's my situation. I have a form A which when open allows me to search
for a specific customer. Once I've found the correct customer (e.g. let's
say record #8 out of 20) I want to pass the associated customer ID back
to another open form B.

Everything works fine as long as I don't move from the first record in
Form A. If I do move from the first record I get the customer ID for the
first record being passed back to form B rather than record #8.

I've looked at the help menus around bookmarks but just get a little more
confused.

Any assistance would sure be appreciated.
 
Back
Top