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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I bind ADO to a Microsoft Access Form?

Status
Not open for further replies.

jazzz

Technical User
Feb 17, 2000
433
US
Hi, I am experimenting with ADO *trying to figure it all out* and I work in Access 2000. I would like to know how do I bind my Access form to ADO. Here is some code I wrote to get a handle on what is happening it finds one record which is what I want it to do but my form still list all the records. What I want to do is allow the underlying form show just the one filtered record.

Dim rst(1 To 2) As ADODB.Recordset
Dim cnn As ADODB.Connection


'* this is the record we are working on
Set rst(1) = New ADODB.Recordset
Set cnn = CurrentProject.Connection
'* the recordset and collection we want to work on
'* it has to be open like this.
rst(1).Open "SELECT * from qrynames", cnn, adOpenStatic, adLockReadOnly

'*requery the database to get our records in order
Me.Requery

If cnn.State = adStateOpen Then
MsgBox "You got a good connection."
'Debug.Print Cnn.ConnectionString
End If


'* create a recordclone here
Set rst(2) = rst(1).Clone

Dim strFilter As String
strFilter = Me("CustID")
Debug.Print strFilter


With rst(2)
.Filter = "custid = " & strFilter
If Not .EOF Then
MsgBox "We are working with our clone."
MsgBox "You have " & rst(2).RecordCount & " records in your clone"
End If
End With

Any guidance is truly appreciated Life's a journey enjoy the ride...

jazzz
 
Here is your solotion

Step #1: Create a form by form wizard and include all fields you want to show in this form.

Step #2: This form must be created in "Datasheet View"

Step #3: Create an another form by using "Design View"

Step #4: Add an unbounded text box in this form in which you want to filter your record (like i give this "txtSearch" name)

Step #5: Create an sub form in this form and cancel the wizard.

Step #6: set the following properties to you sub form.
* Select Source --> to your table or Form ( i preferd to form that you create by wizard in "Data sheet view")

* Lock --> True (so that on there is no way to delete or modify records)

Step #7: In the code window do as follow

Private Sub Text2_Change()
t = "'" & Trim(txtSearch.Text) & "*" & "'"
frmSubForm.Form.Filter = "CustomerName Like " & t
frmSubForm.Form.FilterOn = True
End Sub

Step #8: run the form

and on the changes of the text box you got filterd record in data sheet form

 
Thank you I will give it a try.... Life's a journey enjoy the ride...

jazzz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top