We help IT Professionals succeed at work.

MS Access 2003 - VBA code to copy 1 field to another in the same form

kevin1478
kevin1478 asked
on
Dear Experts
I have a form named address.  The form contains fields named:
Business address
Invoice Address

I want to add a button to the form that will copy the details in business address to invoice address.

The actual form is slightly more complicated but if I can understand the above then I will be able to adapt and apply it.

Can someone please help with the VBA?

Thank you.
Comment
Watch Question

If they are both on the same form then in your Button's On Click event procedure you can

Me!InvoiceAddress = Me!txtBusinessAddress

Cheers, Andrew

Author

Commented:
Thank you.

Ive implemented the code as suggested and I get the error:

The expression On Click you entered as the event property setting produced the following error: A problem occurred while Microsoft Office Access was communication with the OLE server or ActiveX Control.

To test the error I added a button using the wizard to close the form and I got the same error.

Any ideas please.
Database and Application Developer
Commented:
try:

Me!InvoiceAddress.setfocus
Me!InvoiceAddress = Me!txtBusinessAddress

Assuming this code is running from the same form as the one with these two text boxes on them.

Mike
Mike EghtebasDatabase and Application Developer

Commented:
correction...

Assuming this code is running from the same form as the one with these two text boxes on it.
You must ensure you get the names of the controls correct. Looking at what you said in the first posting it could be

Me![Invoice Address] = Me![Business Address]

Cheers, Andrew

Author

Commented:
Thank you. All working.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.