Automatically populate a form field

L

Leah

If I have 2 forms, one being the main form and the second
being form two, how can I populate a field in form 2 when
it is triggered by the main form?

For instance, If I select and option button in the main
form that triggers form 2, I would like the name of the
Customer from the main form to be populated in the form 2
CustomerName field.

Any help would be appreciated. Thanks!!
 
G

Gerald Stanley

If Form2 is being opened as non-modal, your code should
look something like
DoCmd.OpenForm "Form2"
Forms!Form2!txtCustomerName = Me.txtCustomerName

You will have to change txtCustomerName to the control
names that you have on your forms.

Hope This Helps
Gerald Stanley MCSD
 
L

Leah

Thank you!

-----Original Message-----
If Form2 is being opened as non-modal, your code should
look something like
DoCmd.OpenForm "Form2"
Forms!Form2!txtCustomerName = Me.txtCustomerName

You will have to change txtCustomerName to the control
names that you have on your forms.

Hope This Helps
Gerald Stanley MCSD
.
 
L

Leah

Okay this worked but now I notice that when form 2 opens,
I am forced to jump through the records in order to find
the corresponding one. It starts with the first record in
the form 2 table rather than the record that corresponds
to the Main Form. Thoughts?
 
G

Gerald Stanley

It sounds like you need to change the DoCmd.OpenForm to
include a where parameter e.g.
DoCmd.OpenForm "Form2",,,"yourColumn = '" & Me.txtField & "'"

You will have to change yourColumn and txtField to suit
your app. I have assumed that the joining column is a text
field. If it is a number, you sshould drop the '
surrounding Me.textField

Hope This Helps
Gerald Stanley MCSD
 
L

Leah

Actually what I end up doing was setting the DataEntry
Property to yes on Form2 and it works now. Thanks for your
help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top