Search for Value in One Field Only

G

Guest

I have a command button on a form with the following code in the On Click
procedure:

Private Sub Command15_Click()
On Error GoTo Err_Command15_Click

Me![LastName].SetFocus
Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_Command15_Click:
Exit Sub

Err_Command15_Click:
MsgBox Err.Description
Resume Exit_Command15_Click

End Sub

I set the focus on the Last Name so the user could search for an employee by
the last name without having to click the cursor in the last name field.

The problem is that, when the user doesn't know how to spell the last name
exactly, they key in a portion of the name and change the Match field to "Any
Part of Field". When they do this, Access searches and stops on all fields
containing the criteria they entered and not just in the Last Name field.

Is there a way to keep the focus in the Last Name field so that it doesn't
search other fields (like the department field, etc.)?
 
F

fredg

I have a command button on a form with the following code in the On Click
procedure:

Private Sub Command15_Click()
On Error GoTo Err_Command15_Click

Me![LastName].SetFocus
Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_Command15_Click:
Exit Sub

Err_Command15_Click:
MsgBox Err.Description
Resume Exit_Command15_Click

End Sub

I set the focus on the Last Name so the user could search for an employee by
the last name without having to click the cursor in the last name field.

The problem is that, when the user doesn't know how to spell the last name
exactly, they key in a portion of the name and change the Match field to "Any
Part of Field". When they do this, Access searches and stops on all fields
containing the criteria they entered and not just in the Last Name field.

Is there a way to keep the focus in the Last Name field so that it doesn't
search other fields (like the department field, etc.)?

Here is a generic method.

Me.LastName.SetFocus
DoCmd.FindRecord InputBox("What name?"), acAnywhere, , acSearchAll, ,
acCurrent, True

Look up the FindRecord method in VBA help.
 
P

phuser

Is this kind of Lookup available in a Subform?

fredg said:
I have a command button on a form with the following code in the On Click
procedure:

Private Sub Command15_Click()
On Error GoTo Err_Command15_Click

Me![LastName].SetFocus
Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_Command15_Click:
Exit Sub

Err_Command15_Click:
MsgBox Err.Description
Resume Exit_Command15_Click

End Sub

I set the focus on the Last Name so the user could search for an employee
by
the last name without having to click the cursor in the last name field.

The problem is that, when the user doesn't know how to spell the last
name
exactly, they key in a portion of the name and change the Match field to
"Any
Part of Field". When they do this, Access searches and stops on all
fields
containing the criteria they entered and not just in the Last Name field.

Is there a way to keep the focus in the Last Name field so that it
doesn't
search other fields (like the department field, etc.)?

Here is a generic method.

Me.LastName.SetFocus
DoCmd.FindRecord InputBox("What name?"), acAnywhere, , acSearchAll, ,
acCurrent, True

Look up the FindRecord method in VBA help.
 

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

Similar Threads


Top