我想将“字段的任何部分”设为默认值(Access VBA)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17118000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 21:39:25  来源:igfitidea点击:

I'd like to make "Any Part of Field" Default (Access VBA)

vbams-accessms-access-2010ms-access-2007

提问by user2487679

In a simple Find action dialog box on an MSAccess (2007) form I want to make "Any Part of Field" the default value when the Find and Replace box appears.

在 MSAccess (2007) 表单上的一个简单的“查找”操作对话框中,我希望在出现“查找和替换”框时将“字段的任何部分”设为默认值。

The actual default value is "whole field". I though that I could change that with the following line:

实际默认值为“整个字段”。我想我可以用下面的行来改变它:

DoCmd.FindRecord " ", acAnywhere, , , , , False

But that doesn't make any difference. The rest of the code works fine (associated with a command button). But that above line does nothing whether it's there or not. Please help. I have the following code:

但这没有任何区别。其余代码工作正常(与命令按钮相关联)。但是无论是否存在,上面的那条线都没有任何作用。请帮忙。我有以下代码:

Private Sub AppNAppFind_Click()
On Error GoTo AppNAppFind_Click_Err

On Error Resume Next
Err.Clear

DoCmd.FindRecord " ", acAnywhere, , , , , False
DoCmd.RunCommand acCmdFind


If (MacroError <> 0) Then
    Beep
    MsgBox MacroError.Description, vbOKOnly, ""
End If


AppNAppFind_Click_Exit:
   Exit Sub

AppNAppFind_Click_Err:
   MsgBox Error$
   Resume AppNAppFind_Click_Exit

I'm using Access 2007.

我正在使用 Access 2007。

回答by Gord Thompson

The following code works for me in Access 2010.

以下代码在 Access 2010 中对我有用。

Private Sub myFind_Click()
DoCmd.GoToControl "=[Screen].[PreviousControl].[Name]"
DoCmd.FindRecord " ", acAnywhere, False, acSearchAll, False, acCurrent, False
DoCmd.RunCommand acCmdFind
End Sub

I verified that the Access default for "Find" is "Whole Field" on this machine, yet when I click my button the Find dialog has "Any Part of Field" selected for "Match".

我验证了这台机器上“查找”的访问默认值是“整个字段”,但是当我单击我的按钮时,“查找”对话框为“匹配”选择了“字段的任何部分”。

回答by bgmCoder

I'm not sure if this is an option in Access 2007, but in Access 2016, you can go to File > Options > Client Settingsand look for Default find/replace behaviourand change it from Fast searchto General searchand it will set the default find settings to Look in: Current documentand match in Any Part of Field.

我不确定这是否是 Access 2007 中的一个选项,但在 Access 2016 中,您可以去File > Options > Client Settings查找Default find/replace behaviour并将其更改Fast searchGeneral search,它将默认查找设置设置为查找:Current document并匹配Any Part of Field.

This setting is for the client and will be effective in any access db you open and is persistent.

此设置适用于客户端,将在您打开的任何访问数据库中有效并且是持久的。