Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

How To Refresh a Parameterized DataReport

MORE INFORMATION
Open a new Standard EXE Project in Microsoft Visual Basic. Form1 is created by
default.
Add a DataEnvironment (DataEnvironment1) and a DataReport (DataReport1) to the
2.
project.
Add a Connection (Connection1) to the DataEnvironment pointing to NWIND.MDB
3.
(or Northwind.MDB) through the Microsoft Jet 4.0 OLE DB Provider.
Add a Command (Command1) to Connection1, with the following properties:
CommandType: adCommandText
CommandText: Select * From Employees Where HireDate < ?
In the Parameters tab:
4.
Name: pDate
Direction: Input
Data Type: adDBTimeStamp
Host Data Type: Date (VT_DATE)
In the DataReport, set the following properties:
5. DataSource: DataEnvironment1
DataMember: Command1
Drag the following fields from the DataEnvironment into the Detail section of the
DataReport:
EmployeeID
6.
FirstName
LastName
HireDate
Add a TextBox (Text1) and a CommandButton (Command1) to the form. Add the
following code:
1.

Option Explicit
Private Sub Command1_Click()
Load DataEnvironment1
7. With DataEnvironment1
If .rsCommand1.State <> 0 Then .rsCommand1.Close
.Command1 CDate(Text1.Text)
End With
DataReport1.Refresh
If DataReport1.Visible = False Then DataReport1.Show
End Sub

Save the project and run it. Enter the following dates in the TextBox and click the
8. CommandButton after each one:
1/1/95

1/1/94
1/1/93
1/1/92
You can see the report refresh showing only those employees hired prior to the date
entered.

APPLIES TO

Microsoft Visual Basic 6.0 Professional Edition


Microsoft Visual Basic 6.0 Enterprise Edition

You might also like