Automatically populate a form field

  • Thread starter Thread starter Leah
  • Start date Start date
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!!
 
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
 
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
.
 
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?
 
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
 
Actually what I end up doing was setting the DataEntry
Property to yes on Form2 and it works now. Thanks for your
help.
 
Back
Top