Macro: Transfer Text from Form to Report
(VB: Transfer Text from Form to Report)
In this How To, I will show you how to transfer data from textbox on form to report. Data on the textbox is not stored in the table. For example below, I have two textboxes on the form for start and end date. I want to open a report by the date range from the start date and end date that I enter on the form. I also want the date range to show on the report as well.
Step 1 Add two textboxes on form (Main Menu form)
- Add the first unbound textbox and name it “txtStartDate” for a start date.
- Add the second unbound textbox and name it “txtEndDate” for the end date.
Step 2 Add macro code to open report
Under the design view mode, click on an Account Detail button and select “Embedded Macro” under the On Click event.
Macro Code:
Macro Code How it works:
- Check if both the Start Data and End Date are entered
- Display a message if the Start Date or End Date is not entered
- If both dates are entered then set both dates to a temp variable (tempStartDate & tempEndDate)
- Open report with a record criteria from Start Date to End Date
- If there is an error then show an error message and resume next step
Step 3 Add two textboxes on report
- Add the first unbound textbox for a start date.
- Add the second unbound textbox for the end date.
Step 4 Link Start Date textbox on report
- Double Click on the From Date textbox (or Start date)
- Click on a Data tab of Property Sheet
- Update Control Source = “=[TempVars]![tempStartDate]”
Step 5 Add link End Date textbox on report
- Double Click on the To Date textbox (or End date)
- Click on a Data tab of Property Sheet
- Update Control Source = “=[TempVars]![tempEndDate]”
Step 6 Complete and Testing
- Entering two dates on the Start Date and End Date boxes
- Click on Account Detail button
As Result: the Start Date and End Date on form will show on the report of From Date and To Date as shown below.