Auto fill a text field based on a checkbox

T

TinaR

I'm using Access 2007. I have a form with a tab control and two pages. On
the first page, I have text boxes set up to enter contact information (name,
address, city, state, etc. ). On the second page, I have similar text boxes
set up for a second contact person's info. If the info is the same, I don't
want to have to re-type it on the second page, so I added a checkbox to the
second page asking if the contact info is the same. If the checkbox is
checked, I would like to autopopulate the contact info on the second page
with the same contact info from the first page. Also, if the checkbox is
unchecked, I'd like the text boxes to go back to blank. Can this be done? I
thought I posted this question yesterday but couldn't find my post. Thanks
in advance.

Tina
 
A

Arvin Meyer [MVP]

Try this code (untested):

Private Sub chkWhatever_AfterUpdate()
If Me.chkWhatever = True Then
Me.txtAddress2 = Me.txtAddress1
Me.txtCity2 = Me.txtCity1
' etc.
Else
Me.txtAddress2 = ""
Me.txtCity2 = ""
' etc.
End If
End Sub
 
T

TinaR

How odd. I thought I posted my reply but it never showed up....
Thanks for your reply. I must be doing something wrong because it didn't
work. I substituted my information into the code you provided. Below is my
code:

Private Sub IsRxContactSameAsPurchasingContact_AfterUpdate()
If Me.IsRxContactSameAsPurchasingContact = True Then
Me.PharmacyContactFirstName = Me.PurchasingManagerFirstName
Else
Me.PharmacyContactFirstName = ""
End If

End Sub

I'm not sure what I'm doing wrong as it seems pretty straightforward. Does
it matter that the first person's contact info (PharmacyContactFirstName) is
on the first page of my tab control and the second person's contact info
(PurchasingManagerFirstName), as well as the checkbox, are on the second page
of the tab control?

Thanks for your help!
Tina
 
L

Linq Adams via AccessMonster.com

No, it doesn't matter. Unless you're dealing with subforms on the tabbed
pages, which you don't mention, referencing controls on either tabbed page is
done as it they were on a simple, straight forward form.

Since you're using 2007, the question has to be asked: does any code run?

Code does not run in 2007 unless your database resides in a folder that has
been declared a “trusted†location.

To trust your folder, click:

Office Button (top left)
Access Options (bottom of dialog)
Trust Center (left)
Trust Center Settings (button)
Trusted Locations (left)
Add new location (button)

Only other thing I could think of would be if one of your textbox names were
misspelled.
 
T

TinaR

THANK YOU!!! This works perfectly now. I didn't know about the trusted
location in 2007.
 

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