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
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