Customize Find...

J

jsc3489

I've created a simple 'Find Record' button.
Is it possible to set defaults within 'Finds' parameters code?

ex. Have the 'Look in:' to just be the 'Form' and 'Match:' to just be 'Any
Part of Field' etc.
 
A

Allen Browne

You can set the options via:
Tools | Options | Edit/Find | Default Find/Replace Behavior

If you want to do it programmatically, use GetOption or SetOption with:
"Default Find/Replace Behavior"
 
J

jsc3489

Thank you for your reply.
My Access is missing the help files for VB and it can't get it to install,
so...

If you could pleae re-write my code to reflect my OP (or direct me to write
it) .
I need it to default to:

Look in: Sales
Match: Any Part of Field
Search: All

and take out the 'Replace' function.

The code:
--------------------------------------------------------
Private Sub Findit_Click()
On Error GoTo Err_Findit_Click

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

Exit_Findit_Click:
Exit Sub

Err_Findit_Click:
MsgBox Err.Description
Resume Exit_Findit_Click

End Sub
--------------------------------------------------------

Thank you so much.
--
I reject your reality and substitute my own.

Promote hydrogen - one of the best "clean" fuels there are!


Allen Browne said:
You can set the options via:
Tools | Options | Edit/Find | Default Find/Replace Behavior

If you want to do it programmatically, use GetOption or SetOption with:
"Default Find/Replace Behavior"
 
A

Allen Browne

I think it might be a useful thing to do to solve the problem with the help
file. It really makes it easier to figure out how to write the code.

You can then see how to use SetFocus and SetOption.
You cannot remove the Replace tab.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

jsc3489 said:
Thank you for your reply.
My Access is missing the help files for VB and it can't get it to install,
so...

If you could pleae re-write my code to reflect my OP (or direct me to
write
it) .
I need it to default to:

Look in: Sales
Match: Any Part of Field
Search: All

and take out the 'Replace' function.

The code:
--------------------------------------------------------
Private Sub Findit_Click()
On Error GoTo Err_Findit_Click

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

Exit_Findit_Click:
Exit Sub

Err_Findit_Click:
MsgBox Err.Description
Resume Exit_Findit_Click

End Sub
 
J

jsc3489

About a month or so ago, I spent an entire day trying to get the help files
to install.
The problem is this OEM version of Office from Dell and it's been a goose
chase between MS and Dell to get this to work. I have the CD, however it's
OEM like I said and Access can't find the req'd files. Same thing happend to
my Exel and 'Input Mask...' functions, req'd files not found. So I finally
gave up and have been hounding these NG's for help with my issues.
 
J

jsc3489

I found my answer.
Source: somewhere in
http://groups.google.com/groups?q=microsoft.public.access+find+button&start=20&hl=en&

-----------------------------------------------------------
By Dirk Goldgar, MS Access MVP

Okay, here's what I have done to make something that seems to do what
you're asking. The idea is to have a simple popup search form that
operates very similarly to the way the built-in Find dialog would work
if the proper options were selected, but without displaying anything
more than the bare minimum.

Create a new form in design view. Set the following properties for the
form itself:


Format tab
-----------
Caption: Find
Default View: Single Form
Scroll Bars: Neither
Record Selectors: No
Navigation Buttons: No
Dividing Lines: No
Border Style: Dialog

Other tab
-----------
Pop Up: Yes


Turn off the control wizards and add the following controls:

(1) a text box with its associated label. Name the text box
"txtFindWhat". Set the caption of the label to something like "Enter
what you want to find:".

(2) a command button. Name the button "cmdFind" and set its caption
to "Find".

(3) optionally, a label to go over or beside the button, with a
caption along the lines of "Then click this button:".

Adjust the sizes, shapes, and positions of these controls to suit you.

Save the form now (without closing it), giving it the name
"Find Record".

Click the "Code" button on the toolbar, or else click menu items View ->
Code. That will put you in the VB Editor looking at the newly created
code module for this form. Copy the code below (between the "'-----
start of code -----" and "'----- end of code -----" lines) and paste it
over whatever may currently be displayed in the form's module:


'----- start of code -----
Option Compare Database
Option Explicit

Dim mstrFormToSearch As String

Private Sub cmdFind_Click()

Static strLastFind As String
Dim ctlFocus As Access.Control
Dim strTemp As String
Dim I As Integer

If IsNull(Me.txtFindWhat) Then Exit Sub

With Forms(mstrFormToSearch)

.SetFocus

Set ctlFocus = .ActiveControl

On Error Resume Next
strTemp = ctlFocus.ControlSource
If Err.Number <> 0 Then
For I = 0 To .Controls.Count - 1
Set ctlFocus = .Controls(I)
If ctlFocus.Enabled = True Then
Err.Clear
strTemp = ctlFocus.ControlSource
If Err.Number = 0 Then
Exit For
End If
End If
Next I
End If
ctlFocus.SetFocus
On Error GoTo 0

End With

If Me.txtFindWhat = strLastFind Then
DoCmd.FindNext
Else

DoCmd.FindRecord _
Me.txtFindWhat.Value, _
acAnywhere, _
False, _
acSearchAll, _
False, _
acAll, _
True

strLastFind = Me.txtFindWhat

End If

End Sub

Private Sub Form_Open(Cancel As Integer)

On Error Resume Next
mstrFormToSearch = Screen.ActiveForm.Name

If Len(mstrFormToSearch) = 0 Then
MsgBox "There's no active form to search!"
DoCmd.Close acForm, Me.Name, acSaveNo
End If

End Sub
'----- end of code -----


Click menu items Debug -> Compile (your project). If any compile errors
were found, you'll hjave to fix them and recompile. When you get a
clean compile, click the Save button on the toolbar.


Switch back to the database application window. Save and close
Find Record.


Now open the form you want to to use this search function on. Put a
command button on the form, name it "cmdSearch" (for example), and
create this event procedure for its Click event:


'----- start of search-button code -----
Private Sub cmdSearch_Click()

DoCmd.OpenForm "Find Record"

End Sub
'----- end of search-button code -----


Compile and save that form.


That ought to do it. Clicking the search button should open your find
dialog form, on which you can enter what you want to search for and
click the Find button to find the first record and field that contains
it. If you then click the Find button again -- without modifying the
search text -- it should find the next occurrence of that text, and so
on.


Please bear in mind that this is fairly rough, hasn't been tested in a
wide variety of circumstances, and has no error-handling. Any polish is
up to you. Let me know how it works out.

From Dirk Goldgar, MS Access MVP
 
Top