Home  |  About  |   Search   

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

RunCommand Constants

Terms of Use


 

General: Access 2000: Hiding Replace Tab in Find/Replace Dialog

Author(s)
Dev Ashish

The Find and Replace dialogs, separate dialogs in prior Access versions and invoked by the keystrokes Control-F and Control-H respectively (or by calling RunCommand) respectively, are now merged together in Access 2000 to form a tabbed dialog.

Some developers have expressed their concerns, via email and newsgroup posts, about the new dialog that they are not comfortable with the users having such an easy access to the Replace portion of the dialog, when all they want to use  is the Find  functionality.

Access 2000 does not provide any built in way to customize the new Find/Replace dialog.  However, if you mark the form or the table as Read-Only before calling the dialog from code, Access will automatically hide the Replace tab, since the user cannot make any changes in read-only mode.

The following procedures show how to open a form or a table in read-only mode and then call the Find/Replace dialog from code.

' ***** Code Start *********
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Sub sFindReplaceInForm(strFormName As String)
On Error GoTo ErrHandler

Const ERR_GENERIC = vbObjectError + 6666

    ' Open the form
    DoCmd.OpenForm strFormName, _
                                        acNormal

    ' now set it to ReadOnly
    ' The readonly mode will prevent the Replace
    ' dialog from showing up in the tab
    With Forms(strFormName)
        .AllowAdditions = False
        .AllowDeletions = False
        .AllowEdits = False
    End With

    ' select the Form in the UI
    DoCmd.SelectObject acForm, _
                                    strFormName, _
                                    False

    ' Display the Find/Replace dialog
    DoCmd.RunCommand acCmdFind

ExitHere:
    Exit Sub
ErrHandler:
    Resume ExitHere
End Sub

Sub sFindReplaceInTable(strTableName As String)
On Error GoTo ErrHandler

Const ERR_GENERIC = vbObjectError + 6666

    ' Open the Table
    ' The readonly mode will prevent the Replace
    ' dialog from showing up in the tab
    DoCmd.OpenTable strTableName, _
                                        acViewNormal, _
                                        acReadOnly

    ' select the table in the UI
    DoCmd.SelectObject acTable, _
                                    strTableName, _
                                    False

    ' Display the Find/Replace dialog
    DoCmd.RunCommand acCmdFind

ExitHere:
    Exit Sub
ErrHandler:
    Resume ExitHere
End Sub
' ******** Code End *********

1998-2009, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer