Re: populating a field in a record

alicejwz

Registered User.
Local time
Today, 08:34
Joined
Jul 9, 2003
Messages
91
Re: populating a field in a record

Hi, I have a question on populating a field on a form from another form. I have a form(frm_customer) that opens to a filtered form(frm_ear). W/i the frm_ear user wants to populate the customer id field from frm_customer when add a new record through record selectors control in Access.

In click event in frm_customer

Private Sub view customer ears_Click()
On Error GoTo Err_Command32_Click
Dim stDocName As String

stDocName = "ear"
DoCmd.OpenForm stDocName, , , "[customer id]=" & Me![customer ID]


Exit_view customer ears_Click:
Exit Sub

Err_view customer ears_Click:
MsgBox Err.Description
Resume Exit_view customer ears_Click

End Sub

I'm created a button on frm_ear and saved the customer id to a variable before moving to the new record.

Private Sub cmdAdd_record_Click()
On Error GoTo Err_cmdAdd_record_Click
Dim cust_id As Integer

cust_id = Me![customer ID].Value
DoCmd.GoToRecord , , acNewRec
Me![customer ID].Value = cust_id

Exit_cmdAdd_record_Click:
Exit Sub

Err_cmdAdd_record_Click:
MsgBox Err.Description
Resume Exit_cmdAdd_record_Click

End Sub

Is there a better way to do this?What is the code I need to populate the customer id field from record selectors control ? Thanks much!
 
you should use the OpenArgs. Search this forum for OpenArgs, there are several threads covering this issue.
 
Re: populating a field in a record

Correction. It's the navigation buttons I like to add code to populate a field in the new record or any suggestions. Thanks!

I tried openargs property it only sets the form to open to a specific record not for new record.
 
OpenArgs is the solution:

Code:
DoCmd.OpenForm "FormName", , , , acFormAdd, acDialog, [FieldName]

then in the onLoad of the form you want to open and add new record in put the following:

Code:
If Me.OpenArgs <> "" Then
Me.FieldName = Me.OpenArgs
End If
 
Re: Populating a field in a new record

Thanks maxmangion for your responses.

I got it working, except I had to place on Current event. Thanks much!
 

Users who are viewing this thread

Back
Top Bottom