Link to home
Start Free TrialLog in
Avatar of sjmmajor
sjmmajor

asked on

Data Report with data environment

Can you use a parameter or filter so that when someone runs the report (for example: the can select a date) it will only show that data?  And how would you do that?  Can you give me an example?

Avatar of gafoorgk
gafoorgk

yes u can. if u have already defined DataEnvironment and Command objects use the following code as a template

    With deConfiguration
        If (.rscmnAreaList.State = adStateOpen) Then  .rscmnAreaList.Close
       
        With .Commands("cmnAreaList")
            .CommandText = _
                    "SELECT * FROM AREA " & _
                    "WHERE  (AREA_NAME LIKE @AreaName) " & _
                     "ORDER BY AREA_NAME"
            .Parameters("@AreaName").Value = strAreaName
         End With

        .cmnAreaList
    End With


u can also create the same query in design time. then automatically @AreaName will appear in Parameters tab of Command object property dialog box, for which u can set variables in run time.
Or, like this

strSQL = "SELECT * FROM MYTable WHERE AREA_NAME LIKE '" & @AreaName & "' ORDER BY AREA_NAME"  
With DE.rsCmd1
    If  .State=adStateOpen  Then .Close
    .Source = strSQL
    .Open
End With

Also, please read this item as to why not to use Data Enviroment in your code:
https://www.experts-exchange.com/questions/20766815/Reasons-not-to-use-Data-Enviroment-control-in-VB6.html
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sjmmajor

ASKER

Thanks for everyones help!