How to Copy a Text Box Value Using an Access Command Button
Question details
The user needs a method to duplicate data from one text box to another within a form using an Access command button.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Designing a database form where clicking a button automatically copies a value between specific text boxes.
- Observed behavior
- The user is looking for the correct macro action (such as SetValue) or VBA method to transfer the value seamlessly without utilizing the system clipboard.
Ensure your Access form is open in Design View and that both the source and destination text boxes have identifiable names (e.g., txtSource and txtDestination).
Use the SetValue Macro Action
The simplest way to copy a value without relying on the system clipboard is to assign the SetValue macro within the button's On Click event.
This method updates the destination text box instantly when the button is pressed. It bypasses the system clipboard, making it more robust than typical copy-paste commands like acCmdCopy.
Right-click your form in the navigation pane and select 'Design View'.
Select the command button, press F4 to open the Property Sheet, and click on the 'Event' tab.
Click the ellipsis (...) next to the 'On Click' property and choose 'Macro Builder'.
From the 'Add New Action' dropdown, select 'SetValue'. If it does not appear, click 'Show All Actions' in the ribbon first.
In the 'Item' box, enter the name of your destination text box (e.g., [DestinationBoxName]). In the 'Expression' box, enter the name of the source text box (e.g., [SourceBoxName]). Save and close the macro.
Use VBA Code for Direct Assignment
For more advanced configurations, using a simple VBA script is incredibly fast and allows for easy expansion if you need to copy multiple fields at once.
Looking for a Powerful, Lightweight Office Suite?
While WPS Office does not feature a dedicated relational database app like Microsoft Access, it provides a powerful spreadsheet tool that fulfills many data entry, validation, and macro-driven data tracking needs. As a complete Office alternative, it ensures you stay productive without heavy subscriptions.
- 1. Download the software: Visit the official WPS Office website and download the installation package suited for your operating system.
- 2. Install the suite: Run the installer and follow the quick on-screen instructions to set up the software.
- 3. Manage your data: Open WPS Spreadsheets to easily manage tabular data, set up advanced data validation, and use built-in formulas for your tracking needs.

Frequently Asked Questions
Why does the SetValue macro action not appear in the Macro Builder?
In newer versions of Access, SetValue is considered an 'unsafe' action unless the database is stored in a Trusted Location. To view it, you must click the 'Show All Actions' button in the Macro Builder ribbon.
Can I use DoCmd.RunCommand acCmdCopy to copy the text box?
While it is possible, DoCmd.RunCommand acCmdCopy simulates a user pressing Ctrl+C. It requires you to set focus to the source text box first and relies on the system clipboard, making it much less reliable than the SetValue macro or direct VBA assignment.
Does copying the value automatically save the record in the database?
No, updating the text box via SetValue or VBA only modifies the control locally on the form. The underlying database record is updated only when you save the record manually or navigate to a different row in the form.




