Help me create a serach to search my form PLEASE NO COMBO BOX

K

KR

My Table is called Phone Log
My Main Form is called Phone Log Form
My Subform is called Phone Log SUBFM

When I open my Main Form (Phone Log FM) I click on a command button I
created and my Subform pops up. On my subform I have 4 unbound text boxes
(Patients_Name, Callers_Name, Serial#, and Card#). I want to be able to type
in any of the unbound boxes and click on my search button at the bottom of my
form and if what I typed in matches I want my Main Form (Phone Log) to pop
back up with that record on it. Can anyone please help me I have been
surfing the internet for days and nights trying to figure this out.

I also have a another form 2009 SUBFM and I am trying to create a text box
search where i can type the date in and it will go to the record on this form
that matches the date I typed in.

Any help is MUCH MUCH MUCH appreciated!!!
 
J

Jeanette Cunningham

Hi KR,

Here is some code from one of my apps.
The code is for a text box called txtFilterPart and the field is called
PartDescr

You can just repeat these lines-->
If Len(Me.txtFilterPart & vbNullString) > 0 Then
strWhere = strWhere & "(PartDescr Like """ & Me.txtFilterPart &
"*"") AND "
End If

for each text box on your search form.

---------------------------
Private Function FilterMe()
' Statement (A) is a desirable precaution
' whenever manipulating focus on controls
On Error Resume Next ' (A)

Dim strWhere As String
Dim lngLen As Long
Dim ctlLast As Access.Control


' Last active control
Set ctlLast = Screen.ActiveControl

' Take focus away from filter controls so that
' the contents get updated
Me.cmdReset.SetFocus

If Len(Me.txtFilterPart & vbNullString) > 0 Then
strWhere = strWhere & "(PartDescr Like """ & Me.txtFilterPart &
"*"") AND "
End If

'Chop off the trailing " AND ", and use the string as the form's Filter.
'See if the string has more than 5 characters (a trailng " AND ") to
remove.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
Me.FilterOn = False

Else
strWhere = Left$(strWhere, lngLen)
'debug.Print strWhere
'Finally, apply the string as the form's Filter.
End If
ctlLast.SetFocus
With Me
.Filter = strWhere
.FilterOn = True
End With
End Function
 
K

KR

For some reason it's not working :(

Jeanette Cunningham said:
Hi KR,

Here is some code from one of my apps.
The code is for a text box called txtFilterPart and the field is called
PartDescr

You can just repeat these lines-->
If Len(Me.txtFilterPart & vbNullString) > 0 Then
strWhere = strWhere & "(PartDescr Like """ & Me.txtFilterPart &
"*"") AND "
End If

for each text box on your search form.

---------------------------
Private Function FilterMe()
' Statement (A) is a desirable precaution
' whenever manipulating focus on controls
On Error Resume Next ' (A)

Dim strWhere As String
Dim lngLen As Long
Dim ctlLast As Access.Control


' Last active control
Set ctlLast = Screen.ActiveControl

' Take focus away from filter controls so that
' the contents get updated
Me.cmdReset.SetFocus

If Len(Me.txtFilterPart & vbNullString) > 0 Then
strWhere = strWhere & "(PartDescr Like """ & Me.txtFilterPart &
"*"") AND "
End If

'Chop off the trailing " AND ", and use the string as the form's Filter.
'See if the string has more than 5 characters (a trailng " AND ") to
remove.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
Me.FilterOn = False

Else
strWhere = Left$(strWhere, lngLen)
'debug.Print strWhere
'Finally, apply the string as the form's Filter.
End If
ctlLast.SetFocus
With Me
.Filter = strWhere
.FilterOn = True
End With
End Function
 
J

John W. Vinson

For some reason it's not working :(

"Not Working" isn't much help, KR. What is your actual code? What are your
actual control names? Do you get compile errors, wrong results, no results,
your monitor catches fire...?

Jeanette's very good but she can't solve a problem she can't see!
 
J

Jeanette Cunningham

That function FilterMe is called from the Change event of the filter text
box.
I also set the cursor to go to the end of the field for the database.
Each time user types in the text box, the cursor moves to the end of the
typing ready for the next letter.
That is in the access options for 'behavior entering field'.
Does this help?

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top