Search only on current field to unchecked

  • Thread starter Thread starter Steven
  • Start date Start date
S

Steven

I am doing this:

Screen.PreviousControl.SetFocus
SendKeys "%ha%ru%e%n", False
DoCmd.RunCommand acCmdFind

For this particular form I want to open the Find dialog box with the "Search
only on current field" to always be unchecked. But if I use the dialog box
and then run the code again it will switch it to Checked. Then next time to
Unchecked and back and forth. How can I determine if the Checkbox is checked
or not so I will know whether or not to include the ....%e.....?

Thank you for your help,

Steven
 
There is no built-in way to do that. The options depend on your programming
skills. You could keep a global variable that remembers if your code has
already unchecked the box. Obviously not ideal if the user could have
unchecked it.
You could write your own Search dialog. A bit of work, but then you are in
full control.
You could use Windows API functions to determine the state of the checkbox.
That requires advanced programming skills.

Tom van Stiphout
Microsoft Access MVP
 
You can set the Find defaults by performing your own temporary search
first using the desired parameters.

Here is a sample subroutine to do so. This version uses an internal
table named "UsysProperty" and searches for a known record, but you can
substitute your own small table name, or use any table you have open.

Watch out for word-wrapping.

- Steve

' Set the specified defaults for the Find tool by invoking it once on a
sample table.
' This seems to be the only way to set a default of not formatted
(otherwise Access Find defaults to search as formatted).
' Also this is a way to immediately set the default MatchCriterion to
acStart or acEntire or acAnywhere, without reopening the database.
' Example: SetFindDefaults acStart, acSearchAll, False, acCurrent '
Find matches start of text, anywhere in the field, unformatted, current
field only

Public Sub SetFindDefaults(MatchCriterion As AcFindMatch,
SearchDirection As AcSearchDirection, isSearchAsFormatted As Boolean,
isCurrentFieldOnly As AcFindField)

On Error GoTo ErrExit
DoCmd.Echo False ' reduce flicker
' open any form or table or query
DoCmd.OpenTable "UsysProperty"
' perform a search to set the defaults
DoCmd.FindRecord "Property='Database Type'", MatchCriterion, False,
SearchDirection, isSearchAsFormatted, acCurrent, isCurrentFieldOnly
' close the datasheet
DoCmd.Close acTable, "UsysProperty", acSaveNo
DoCmd.Echo True
Exit Sub

ErrExit:
Err.Clear
End Sub
 
Back
Top