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
April 9th, 2012, 11:28 AM
dglienna
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'
April 9th, 2012, 09:40 PM
princebrainbox
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.
April 9th, 2012, 10:25 PM
dglienna
Re: Data Report
Then you shouldn't BIND the table to the control. Create a DYNAMIC QUERY.
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.
April 10th, 2012, 06:21 PM
princebrainbox
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?
April 11th, 2012, 09:20 AM
WoF
Re: Data Report
Remove the On Error Resume Next by commenting it out temporarily and then see if an error message appears.