Question : Access 2003 - VBA - pass customer_id from 1 form to another

Dear Experts,

I have a form named customer, based on a customer table. It has a button and on click a 2nd form opens named customer_record. This is based on a customer_record table.

The customer_record form should open already populated with information relating to the customer on the customer form. The pk is customer_id.

This works when there is an associated record in the underlying customer record table, as youd expect.

However, if the customer does not have a related customer record the 2nd form opens blank, as you expect. In such a situation, I want the ability to enter a customer record in the customer_record form that is automatically associated with the customer on the customer form.  At present, I can enter a record but only if I select the pk of the customer on the customer_record form. The pk does not transfer automatically. I assume this is because it is a new customer_record, that has yet to be made.

I want to be able to open a customer form. Click the button to open the customer_record form and view or add associated records, without having to select the customer pk.

I hope this makes some sense.  Can you please advise? Thank you.


Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
Private Sub Command68_Click()
On Error GoTo Err_Command68_Click
 
    Dim stDocName As String
    Dim stLinkCriteria As String
 
    stDocName = "frm_customer_enquiry"
    
    stLinkCriteria = "[customer_id]=" & Me![tbl_customer_customer_id]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
 
Exit_Command68_Click:
    Exit Sub
 
Err_Command68_Click:
    MsgBox Err.Description
    Resume Exit_Command68_Click
    
End Sub
Open in New Window Select All

Answer : Access 2003 - VBA - pass customer_id from 1 form to another

You can specify teh default value of the Customer_ID control to =Forms!Customer!tbl_customer_customer_id
Alternatively you can set the actual value in the On Before Insert
Me!Customer_ID = Forms!Customer!tbl_customer_customer_id

Cheers, Andrew
Random Solutions  
 
programming4us programming4us