Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro for Find/Next

Status
Not open for further replies.

ProtegeV2

Technical User
Sep 9, 2004
40
0
0
CA
Is it possible to make a macro to change the default setting for the built-in Find/Next method from "Match: Whole Field" to "Match: Any part of Field"?

Thank you.
 
Hi,

I doubt a macro can do it, but I guess VBA can.
Sorry that I cannot contribute more, I've also wondered about this..

Another sollution is to use filters and make your own search-form. More work probably, but it looks more integrated (if you are good on design, that is)..
 
Thru menus:
Tools | Options - Edit/Find tab - I think "Generel Search" is the one you're looking for

Thru code
application.setoption "Default find/replace behavior", 1

I'm not sure, but I think for some of these options Access needs to be restarted

Roy-Vidar
 
Thanks RoyVidar. Can you tell me where do I put the code? In a module??
 
Anywhere where you wish to trigger it;-)
Forms module, standard module...

Point is, I think you'll need to restart Access for a change to take place (or it might just be me not knowing how to refresh such properties), so where you place it might not be so important. But perhaps in the on open event of the first form opening in the database?

Roy-Vidar
 
Hi,

1. enter design view of the form
2. draw the commandbutton (or image, if preferred)
3. right-click the button or image
4. click on the properties
5. go on the action pane (not sure if it's called action)
6. press the textbox where it says "on click". When you see that two buttons on the right appears, click on the one with an arrow pointing downwards, choose the [action] or what it's called.. Not sure about the english term.
7. press the "..." button next to the button on point 6.
8. paste the code

To test the code, press first [CTRL] + to store the VBA, then switch back to access ([ALT] + [TAB]), press the button you pressed to enter designview.. eg. enter normal-mode for the form.

You dont need to restart access..
if you get an error in your code, try to fix it, and then press [F5] in VB.

There is no reason to close VB, untill you are done for the day. More VBA is often needed.

remember to comment your code, as well as ident it!
identing should be like this:

' comment about what this code does
IF something THEN
foo ' comment about foo
ELSE
bar ' comment about bar
END IF

This makes the code easier to read.
Do not comment too much, do not comment too little..

example:

' check for error
IF error = "true" THEN
msgbox("Error!") ' alert user
ELSE
msgbox("no problem mate!") ' run regular code
END IF

eg. your comments does not have to tell in detail what happends!
 
One important tip:
When you work with text-fields, (searching, modifying, etc), you always have to use the .setfocus!

eg. before searching, set the focus to the first textfield you want it to be able to search thru.

Just for information, I here past my search-code.. I use images instead of buttons (custom images, so design looks better). Also I have a tip field, a bunny, which talks the tips in dialouges. It's based on a global variable (defined in (General))

I just implemented RoyVidar's function too.. works perfect :)

anyways, here is the code.. use if you want :)

ps. if you want to use a tip-field, like I do, remember to reset the code, when the mouse moves over the form or any objects.


You just paste this code in all the objects:

knappInfo = "your tiptext"

If lblInfo.Caption <> knappInfo Then lblInfo.Caption = knappInfo

remember to define knappInfo in (General)

Dim knappInfo As String

--

Private Sub knappSoek_Click()


On Error GoTo Err_Kommando163_Click
Application.SetOption "Default find/replace behavior", 1
Løpenr.SetFocus
Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_Kommando163_Click:
Exit Sub

Err_Kommando163_Click:
MsgBox Err.Description
Resume Exit_Kommando163_Click

End Sub

Private Sub knappSoek_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
knappSoek.Picture = "søk_down.bmp"
End Sub

Private Sub knappSoek_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
knappInfo = "Søk etter saker (søker ikke i tilvekst!)"

If lblInfo.Caption <> knappInfo Then lblInfo.Caption = knappInfo

End Sub

Private Sub knappSoek_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
knappSoek.Picture = "søk.bmp"
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top