Need Help in Making a Find Command Button

T

TanyaM

Please help!

I would like to make a find command button the searches the last name field
in my database. What I'd like is when you hit the button it essentially
launches the equivalent to a ctrl F. I can make the button, but when it comes
to writting the code, I'm stumped. Nothing I do seems to work. Please help!

Thanks,
Tanya
 
J

Jerry Whittle

Put something like below on the On Click event of the button. Col1 is the
name of the field that you want to search.

Private Sub cmdFindCountry_Click()
Col1.SetFocus
DoCmd.RunCommand acCmdFind
End Sub

Now the next problem is who to set how you want the search to work. Check
out Application.SetOption.

'Set some database defaults found in Tools, Options
' Put in the Open event of the startup form
' Set Default Locking to Edited Record
Application.SetOption "Default Record Locking", 2
' Set Default Open Mode for Databases to Shared
Application.SetOption "Default Open Mode for Databases", 0
' Set Default Find/Replace Behavior to Start of Field Search
Application.SetOption "Default Find/Replace Behavior", 2

Application.SetOption "ShowWindowsInTaskbar", True

In the case of "Application.SetOption "Default Record Locking", 2" Default
Record Locking has three choices and the one I want is the third so, of
course, I put in 2 for the arguement. That's because it starts numbering at 0
instead of 1.

Put the above code in the Open Event of your opening form. One other strange
thing is that the database may need to be opened and closed twice on the
user's computer for the change to take effect. The first time the database
opens, it makes the changes. The second time the changes are in effect.
 

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