ACC: How to Fill Text Boxes on a Report Using Access BasicID: Q109943
|
Moderate: Requires basic macro, coding, and interoperability skills.
This article describes two methods that you can use to populate (or fill)
controls on a report based on a table or query when you run the report.
This article assumes that you are familiar with Access Basic and with
creating Microsoft Access applications using the programming tools provided
with Microsoft Access. For more information on Access Basic, please refer
to the "Introduction to Programming" manual in Microsoft Access version
1.x, or the "Building Applications" manual, Chapter 3, "Introducing Access
Basic," in version 2.0.
Both of the examples below use Access Basic code to fill a control on a
report based on the Employee List query. The code will fill in the City
field on a report that only contains the Employee ID and Employee Name
fields.
The first example demonstrates how to fill a field using Access Basic
code called from the OnFormat property of the report's detail section:
- Single-Column
- Include both fields
- Sort by Employee Name
- Select Executive style
ControlName: City
ControlSource: <leave empty>
Option Explicit
Function fillrep()
Dim ds as Dynaset, db as Database
Set db=CurrentDB()
set ds=db.CreateDynaset("Employees")
ds.MoveFirst
ds.FindFirst "[Employee ID]=" & Reports![Fill Report1]![Employee _
ID]
Reports![Fill Report1]![City]=ds![city]
End Function
=fillrep()
- Single-Column
- Include both fields
- Sort by Employee Name
- Select Executive style
ControlName: City
ControlSource: <leave empty>
Function fillit()
Dim ds as Dynaset, db as Database
Set db=CurrentDB()
set ds=db.CreateDynaset("Employees")
ds.MoveFirst
ds.FindFirst "[Employee ID]=" & Reports![Fill Report2]![Employee _
ID]
fillit=ds!city
End Function
=fillit()
For an example of how to fill text boxes on a report using Visual Basic,
please see the following article in the Microsoft Knowledge Base:
Q143280 ACC: How to Fill Text Boxes on a Report Using Visual Basic
Keywords : kbusage McrArg
Version : 1.0 1.1 2.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 2, 1999