Find Command Button

J

Jen

On my main form I have a command button for the function Find Records.
However I want it only to search one field.

Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

When I click on the command button it wants to search [Caller]
I want it only to search [DDLID] everytime. Is this possible.

Thanks Jen
 
S

SteveS

Jen,

Are you saying that if you set the focus to [DDLID], the focus moves to
[Caller], then finds records?

If so, change this line - add a single quote at the front (ie - comment out
the line)

' Screen.PreviousControl.SetFocus
^

Then try the code.


HTH
 
J

Jen

This in not what I am looking for. When I and the ' it only searches the
current record. I want it to search all my records but only the field
[DDLID].

I am not sure how to set the Focus to [DDLID] because when the form opens
[Caller] is the first field to be filed out.

Thanks
Jen


SteveS said:
Jen,

Are you saying that if you set the focus to [DDLID], the focus moves to
[Caller], then finds records?

If so, change this line - add a single quote at the front (ie - comment out
the line)

' Screen.PreviousControl.SetFocus
^

Then try the code.


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


Jen said:
On my main form I have a command button for the function Find Records.
However I want it only to search one field.

Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

When I click on the command button it wants to search [Caller]
I want it only to search [DDLID] everytime. Is this possible.

Thanks Jen
 
K

Klatuu

What are you searching for, What are you going to do when you find a match?
What happens when you don't find a match?

See VBA Help regarding DoMenuItem. It was replaced with RunCommand in 97
and only there for backward compatibility.

A better way to execute a search for a specific value in a field is to use
an unbound combo box.
 
S

SteveS

OK,

Would you post the code for your FIND button?

Rather than use FIND, it is easier to filter the recordset.

Like Klatuu said, you could put an unbound text box in the header of the
form and add two buttons. One button would set the filter and the other would
remove the filter.

If [DDLID] is numeric and the text box in the header is named "Text8", the
following code will show only records that match what is entered in the text
box:

(Change Text8 to the name of your text box)

' filter records
Private Sub SetFilterOn_Click()
Me.Filter = "[DDLID] = " & Me.Text8
Me.FilterOn = True
End Sub

' remove the filter
Private Sub SetFilterOff_Click()
Me.FilterOn = False
End Sub


If [DDLID] is text, use the fillowing code:

'filter records
Private Sub SetFilterOn_Click()
Me.Filter = "[DDLID] = '" & Me.Text8 & "'"
Me.FilterOn = True
End Sub

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


Jen said:
This in not what I am looking for. When I and the ' it only searches the
current record. I want it to search all my records but only the field
[DDLID].

I am not sure how to set the Focus to [DDLID] because when the form opens
[Caller] is the first field to be filed out.

Thanks
Jen


SteveS said:
Jen,

Are you saying that if you set the focus to [DDLID], the focus moves to
[Caller], then finds records?

If so, change this line - add a single quote at the front (ie - comment out
the line)

' Screen.PreviousControl.SetFocus
^

Then try the code.


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


Jen said:
On my main form I have a command button for the function Find Records.
However I want it only to search one field.

Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

When I click on the command button it wants to search [Caller]
I want it only to search [DDLID] everytime. Is this possible.

Thanks Jen
 
K

Klatuu

Were I doing it, I would use only one button.

' filter records
Private Sub SetFilter_Click()
If Me.SetFilter.Caption = "Set Filter" Then
Me.Filter = "[DDLID] = " & Me.Text8
Me.FilterOn = True
Me.SetFilter.Caption = "Clear Filter"
Else
Me.FilterOn = False
Me.SetFilter.Caption = "Set Filter"
End If
End Sub


SteveS said:
OK,

Would you post the code for your FIND button?

Rather than use FIND, it is easier to filter the recordset.

Like Klatuu said, you could put an unbound text box in the header of the
form and add two buttons. One button would set the filter and the other would
remove the filter.

If [DDLID] is numeric and the text box in the header is named "Text8", the
following code will show only records that match what is entered in the text
box:

(Change Text8 to the name of your text box)

' filter records
Private Sub SetFilterOn_Click()
Me.Filter = "[DDLID] = " & Me.Text8
Me.FilterOn = True
End Sub

' remove the filter
Private Sub SetFilterOff_Click()
Me.FilterOn = False
End Sub


If [DDLID] is text, use the fillowing code:

'filter records
Private Sub SetFilterOn_Click()
Me.Filter = "[DDLID] = '" & Me.Text8 & "'"
Me.FilterOn = True
End Sub

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


Jen said:
This in not what I am looking for. When I and the ' it only searches the
current record. I want it to search all my records but only the field
[DDLID].

I am not sure how to set the Focus to [DDLID] because when the form opens
[Caller] is the first field to be filed out.

Thanks
Jen


SteveS said:
Jen,

Are you saying that if you set the focus to [DDLID], the focus moves to
[Caller], then finds records?

If so, change this line - add a single quote at the front (ie - comment out
the line)

' Screen.PreviousControl.SetFocus
^

Then try the code.


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

On my main form I have a command button for the function Find Records.
However I want it only to search one field.

Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

When I click on the command button it wants to search [Caller]
I want it only to search [DDLID] everytime. Is this possible.

Thanks Jen
 

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