Form Filter

  • Thread starter Thread starter Somecallmejosh
  • Start date Start date
S

Somecallmejosh

Hello,

I am trying to create a filter on my form that will allow
a user to type in and search for a [lab number] in an
unbound text box. I have it set up so a user types in
the lab number, then clicks a command button that is
supposed to aid in the filtering process. Additionally,
there is a command button which cancels the filtering
process.

I have the following code, but am receiving an error
message (Compile Error - User-defined type not defined)
when attempting this. In the debugger, the "Dim db As
Database" statement is highlighted in grey. I'm not
experienced enough with writing code to know what this
means. Any help would be greatly appreciated.

Sincerely,
Josh

Here's what I have:
______________________________________________________
For the Filter Button:
------------------------------------------------------

Private Sub Command24895_Click()
Dim db As Database
Dim rs As Recordset

If IsNull(Me.TxtKitSearch) = True Then Exit Sub

Set db = CurrentDb
Set rs = db.OpenRecordset("Select [lab#] from data
Where [lab#]='" & Me.TxtKitSearch & "'")

If rs.EOF = True Then
MsgBox "Not Found", , "Search..."
Me.lblFilter.Visible = False
Me.FilterOn = False
Else
Me.Filter = "[lab#]='" & rs![lab#] & "'"
Me.FilterOn = True
Me.lblFilter.Visible = True
End If

db.Close

End Sub
________________________________________________________

For the unbound text box: named TxtKitSearch
--------------------------------------------------------

Private Sub TxtKitSearch_BeforeUpdate(Cancel As Integer)

End Sub

_____________________________________________________
For the Clear Filter Button:
------------------------------------------------------
Private Sub Command24896_Click()

Me.lblFilter.Visible = False
Me.FilterOn = False
Me.TxtKitSearch = Null


End Sub
 
Somecallmejosh wrote:[snip]
I have the following code, but am receiving an error
message (Compile Error - User-defined type not defined)
when attempting this. In the debugger, the "Dim db As
Database" statement is highlighted in grey. I'm not
experienced enough with writing code to know what this
means.
[snip]

This is typically a symptom of a references problem. Most
likely, you are using A2K or AXP and didn't add the DAO
library to your list of library references (Tools menu while
in the VBE). If you have no plan to use the ADO library,
you should uncheck that so you don't run into name conflict
issues.
 
Marsh,

I've unselected the ADO Library, re-opened the report,
and got the same error message. This is code that was
used in another DB, and the appropriate information was
changed (at least I think it was) to meet the needs of
the new DB. I am using A2K... you mention that I should
add the DAO library. I don't see that option under
Tools --> References. Would it fall under some other
heading? How do I add this library? I look forward to
your response.

Sincerely,
Josh

-----Original Message-----
Somecallmejosh wrote:[snip]
I have the following code, but am receiving an error
message (Compile Error - User-defined type not defined)
when attempting this. In the debugger, the "Dim db As
Database" statement is highlighted in grey. I'm not
experienced enough with writing code to know what this
means.
[snip]

This is typically a symptom of a references problem. Most
likely, you are using A2K or AXP and didn't add the DAO
library to your list of library references (Tools menu while
in the VBE). If you have no plan to use the ADO library,
you should uncheck that so you don't run into name conflict
issues.
 
Marsh,

Found the DAO library (under Microsoft DAO 3.6)... What
I am getting now is a Compile Error (Method or Data
Member not found) after clicking the "Filter" button.
The debugger goes to the "Me.lblFilter.Visible = False"
statement and highlights the ".lblFilter". What do these
letters mean? Is there an easier way of setting up this
type of filter, or am I stuck with this method? Again,
as is obvious, my experience with code is incredibly
limited.

Sincerely,
Josh

-----Original Message-----
Marsh,

I've unselected the ADO Library, re-opened the report,
and got the same error message. This is code that was
used in another DB, and the appropriate information was
changed (at least I think it was) to meet the needs of
the new DB. I am using A2K... you mention that I should
add the DAO library. I don't see that option under
Tools --> References. Would it fall under some other
heading? How do I add this library? I look forward to
your response.

Sincerely,
Josh

-----Original Message-----
Somecallmejosh wrote:[snip]
I have the following code, but am receiving an error
message (Compile Error - User-defined type not defined)
when attempting this. In the debugger, the "Dim db As
Database" statement is highlighted in grey. I'm not
experienced enough with writing code to know what this
means.
[snip]

This is typically a symptom of a references problem. Most
likely, you are using A2K or AXP and didn't add the DAO
library to your list of library references (Tools menu while
in the VBE). If you have no plan to use the ADO library,
you should uncheck that so you don't run into name conflict
issues.
.
 
Somecallmejosh said:
Found the DAO library (under Microsoft DAO 3.6)... What
I am getting now is a Compile Error (Method or Data
Member not found) after clicking the "Filter" button.
The debugger goes to the "Me.lblFilter.Visible = False"
statement and highlights the ".lblFilter". What do these
letters mean? Is there an easier way of setting up this
type of filter, or am I stuck with this method? Again,
as is obvious, my experience with code is incredibly
limited.


I can't tell what that is for sure, but it looks like it
might be some kind of (label?) control on your form.
Perhaps you don't want to see whatever it is and should
remove the lines of code that refer to it. Or maybe you do
want it, but forgot to make sure its name is lblFilter.
 
Thank you for all of your help, Marshall. I figured out
that the .lblFilter refers to a Text Label that becomes
visible when the "filter" button is clicked, and becomes
invisible when the "clear filter" button is clicked. It
is working like a charm now. This newsgroup is an
excellent tool for newbies, like me, who are working very
hard to learn the ins and outs of these applications.

Sincerely,
Joshua
 
Back
Top