From a VB Form: Invoke a Report (with DataEnvironment) & USING SQL
Hi,
I am trying to use DataEnvironment1, Connection1 and Command1 with visual basic 6 and produce reports executing SQL commands that use data coming (during run-time) from the user.
A simple example is:
I added a new DataEnvironment1, set the Connection1 and Command1 (using the Properties window) - mean I chose the database (Access) and also, I added a new Report in which I have a text that is bound with the database and also works with the SQL statement of Command1: Select * from ATable where CID = '1'
But in my project, I want '1' to be dynamic, meaning I want the user to write in a textbox (Text1) in a form (Form1) and press a command button (Command1) and this invokes the Report (with : Report.Show )..
Therefore, I want in my SQL statement to join the SQL command with the FORM...
How can I do that???
Re: From a VB Form: Invoke a Report (with DataEnvironment) & USING SQL
Change the sql statement of command1 to use parameters (ie use Select * From ATable Where CID = prmCID). Set the appropriate properties for the Parameter. The DataEnvironment.Command1 method will now contain a argument for the parameter.
VB code to set the parameter and execute the report
VB Code:
Private Sub cmdShowReport_Click()
If DataEnvironment1.rsCommand1.State = adStateOpen Then
DataEnvironment1.rsCommand1.Close
End If
DataEnvironment1.Command1 Text1.Text
DataReport1.Show
End Sub