From a VB Form: Invoke a Report (with DataEnvironment) & USING SQL-VBForums
Results 1 to 2 of 2

Thread: From a VB Form: Invoke a Report (with DataEnvironment) & USING SQL

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    111

    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???

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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:
    1. Private Sub cmdShowReport_Click()
    2.     If DataEnvironment1.rsCommand1.State = adStateOpen Then
    3.         DataEnvironment1.rsCommand1.Close
    4.     End If
    5.     DataEnvironment1.Command1 Text1.Text
    6.     DataReport1.Show
    7. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.