Data Report
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Data Report

  1. #1
    Join Date
    Apr 2012
    Posts
    4

    Data Report

    I created a VB6 program which I linked to MS-Access(.mdb) using AdoData Control. I created a Data Report which displays all the records in the table.

    Now, I want to be able to FILTER any desired record (e.g anybody with a particular FIRSTNAME ) . This means, any time I want to display the records of those with FIRSTNAME = JOHN then I will type JOHN in a textbox control and filter their records alone in the Data Report.

    I need your help to achieve this!!!!!!!!!!!
    This is very very urgent
    Thanks for your concern

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,999

    Re: Data Report

    While there is a FILTER command, which MAY work, in most cases, just change the query to include a
    Code:
    WHERE LNAME = 'JOHN'
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Apr 2012
    Posts
    4

    Re: Data Report

    Thanks for your Quick Reply
    But using Where LNAME = 'JOHN' will limit the query to always retrieve LNAME with JOHN.

    I want a dynamic situation whereby I may want to retrieve any LNAME and not just JOHN

    I need a situation whereby as I type any LNAME in the textbox control on my FORM and click a button (e.g cmdFilter) then it will filter the LNAME so that the Data Report can also display the same filtered records and not all the records in the table.

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,999

    Re: Data Report

    Then you shouldn't BIND the table to the control. Create a DYNAMIC QUERY.

    Here's an article I wrote, with a sample.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,723

    Re: Data Report

    Well, you simply include the contents of the textbox within the query string like
    Code:
    "... WHERE LNAME='" & txtName.Text & "'"
    If txtName.Text would contain Henry then the query string would look like
    SELECT .... WHERE LNAME='Henry'
    The actual name being packed between single quotes.

  6. #6
    Join Date
    Apr 2012
    Posts
    4

    Re: Data Report

    I created the Data report with Data Environment;
    While I bound the text controls to Ado Data Control (Adodc1)


    'Filter Code
    Private Sub cmdFilter_Click()
    On Error Resume Next
    With Adodc1.Recordset
    .MoveFirst
    .Filter = "surname= '" & txtsearch.Text & "'"
    If .EOF Then
    MsgBox "Invalid Data", vbOKOnly, "Search info"
    Adodc1.Refresh
    Else

    End If
    End With
    End Sub

    What could be the problem?

  7. #7
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,723

    Re: Data Report

    Remove the On Error Resume Next by commenting it out temporarily and then see if an error message appears.

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center