PDA

View Full Version : Filter By Form


mhagan
07-09-02, 12:06
I have an Access form that I want to distribute to users who do not have Access. I do not have Microsoft Office Developer or this would be easy.

The form allows the user to filter records based on date of birth, soc sec nbr or any other field on the form. I tried creating a data access page, but I can't filter by form on the data access page.

I also tried creating a form in VB6 using the Access database. I was able to create the form, but I don't know much about coding, and I was not able to replicate the filter by form feature? Anyone with any ideas? I could really use some help!!!!!!!!!!!!!!

Thanks!:D

rnealejr
07-09-02, 22:11
Using vb you can create a recordset object and use a property called filter or a method called find. If you need help starting it, please respond.

Good luck.

mhagan
07-10-02, 09:22
Thank you for your response! I tried creating a text box and a command button. This is the code that I entered:

Private Sub Command1_Click()
Dim adoPrimaryRS As Recordset
Recordset = "Select [Pat Birthdate] FROM tblchartlocator WHERE [Pat Birthdate] Like '%" & Text1 & "%'"
adoPrimaryRS.Refresh
End Sub

When I try to run the subprocedure, I get an error that says:

"Compile error: Member or data member not found."

This is the part that the debugger hilites:

Private Sub Command1_Click()
Dim adoPrimaryRS As Recordset
Recordset = "Select [Pat Birthdate] FROM tblchartlocator WHERE [Pat Birthdate] Like '%" & Text1 & "%'"
adoPrimaryRS.Refresh
End Sub

Thanks again, for any help that you can give me! If you'd like to e-mail me instead of going through the message board, do so at mhagan@boice-willis.com.

rnealejr
07-10-02, 11:25
I am not sure if you are using the recordset object or the ado data control. Try the following - select project-references-ms ado objects 2.x and look at the following code - it is from a ms help file - Your strCnn will be different since you are using ms access:

Dim rstPublishers As ADODB.Recordset
Dim rstPublishersCountry As ADODB.Recordset
Dim strCnn As String
Dim intPublisherCount As Integer
Dim strCountry As String
Dim strMessage As String

' Open recordset with data from Publishers table.
strCnn = "Provider=sqloledb;" & _
"Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "
Set rstPublishers = New ADODB.Recordset
rstPublishers.CursorType = adOpenStatic
rstPublishers.Open "publishers", strCnn, , , adCmdTable

' Populate the Recordset.
intPublisherCount = rstPublishers.RecordCount

' Get user input.
strCountry = Trim(InputBox( _
"Enter a country to filter on:"))

If strCountry <> "" Then
' Open a filtered Recordset object.
Set rstPublishersCountry = _
FilterField(rstPublishers, "Country", strCountry)

If rstPublishersCountry.RecordCount = 0 Then
MsgBox "No publishers from that country."
Else
' Print number of records for the original
' Recordset object and the filtered Recordset
' object.
strMessage = "Orders in original recordset: " & _
vbCr & intPublisherCount & vbCr & _
"Orders in filtered recordset (Country = '" & _
strCountry & "'): " & vbCr & _
rstPublishersCountry.RecordCount
MsgBox strMessage
End If
rstPublishersCountry.Close

End If

Respond if you need additional help.

mhagan
07-10-02, 12:41
THANK YOU! I WILL TRY YOUR SUGGESTIONS!!!!!!!!!!!!!