Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Do you Display a "Filtered" DataGrid? 1

Status
Not open for further replies.

Hiccup

Programmer
Jan 15, 2003
266
US
My setup is VB6/Access2K. I have a DataGrid connected to the Access mdb via an Adodc on my VB6 Form along with a cmdButton.

Can someone tell me the code so that when the cmdButton is clicked the DataGrid will display only the Records where the "DateCompleted" Field is blank. And then when the Form is exited, the DataGrid will "Refresh" to display all of the Records again.

Thanks in advance!
 
One way to do that could be:

Private Sub cmdButton_Click()
Dim myFcriteria as string
Dim rs as recordset
set rs = myAdo.recordset
myFcriteria = "DateCompleted = ''"
rs.filter = myFcriteria
End Sub

to get it back you can either:

rs.refresh

or

rs.filter = ""

and finally,
set rs = Nothing


Eman_2005
Technical Communicator
 
Thanks eman2005 for your suggestion, but I got to work with this code:

Option Explicit
Dim Cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub GetConnection()
If Cn.State = 0 Then
Dim ConnectionString As String

'Database should be in the Application's Path
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\EHicks\RESIDENTIAL PROPERTY MANAGER\RPM.mdb;Persist Security Info=False"

'First Open the Connection before Using it in Recordset
Cn.CursorLocation = adUseClient
Cn.Open ConnectionString
End If
End Sub
Private Sub Command13_Click(Index As Integer)
Call FindData
End Sub
'This sub is used to open a recordset with data that matched the search criteria
'and then shows that to a datagrid named "grdList"
Private Sub FindData()
Dim SQLString As String

'Use the Search Criteria in the Query
SQLString = "SELECT * FROM SortGndsMaintTable WHERE DateCompleted is NULL"

'Close the recordset if it is already open
If rs.State = 1 Then
rs.Close
End If

'Now Open Recordset again with SQLString
Call GetConnection
rs.Open SQLString, Cn, adOpenStatic, adLockOptimistic
'Bind Recordset with Grid
Set DataGrid1.DataSource = rs
End Sub

Here's a star for your help anyway!
 
Thank you for the star.
By the way, every how many stars I get what? ;-))
I just tried to give the simplest answer to your question, but hey, why make simple if you could complicate? :)

Eman_2005
Technical Communicator
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top