vba Microsoft Access 找不到字段“|1”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14780280/
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 19:33:12  来源:igfitidea点击:

Microsoft Access can't find the field '|1'

sqlvbaaccess-vbaruntime-error

提问by Muhnamana

I keep getting a run time error '2465' when running a query via VBA in Access.

在 Access 中通过 VBA 运行查询时,我不断收到运行时错误“2465”。

Error: Microsoft Access can't find the field '|1' referred to in your expression

错误:Microsoft Access 找不到表达式中引用的字段“|1”

I can't seem to find where this issue is occuring. Below is the VBA code that I'm currently using to requery a form.

我似乎无法找到发生此问题的位置。下面是我目前用来重新查询表单的 VBA 代码。

Dim Test As String
Test = "*" & Combo161.Value

Dim strSQL As String
Dim strWhere As String
strWhere = (Chr(34) + Test + (Chr(34)))

'MsgBox (strWhere)

strSQL = "SELECT * FROM Test_Query WHERE TestID " & strWhere

'MsgBox (strSQL)
[Form_Test (subform)].RecordSource = strSQL
[Form_Test (subform)].Requery

The TestIDhad a field formatting of text, rather than a number. Does this matter at all?

TestID有一个字段格式的文本,而不是数量。这有什么关系吗?

采纳答案by Fionnuala

Try:

尝试:

Dim Test As String
Test = "*" & Combo161.Value

Dim strSQL As String
Dim strWhere As String
strWhere = (Chr(34) & Test & (Chr(34)))

'MsgBox (strWhere)

strSQL = "SELECT * FROM Test_Query WHERE TestID Like " & strWhere

'To test
'Debug.print strSQL

If this is a subform, then:

如果这是一个子表单,则:

Me.[Form_Test (subform)].Form.RecordSource = strSQL
''Not needed when changing record source
''Me.[Form_Test (subform)].Form.Requery

You did not have an equals sign / Like and the concatenator in VBA is &, not +, using + can lead to problems with nulls, but in this case, I reckon the problen is the missing Like, that is

您没有等号 / Like 并且 VBA 中的连接符是 &,而不是 +,使用 + 会导致空值问题,但在这种情况下,我认为问题是缺少 Like,即

TestID Like "*something"

You can control the contents of a subform with a combo and a link field:

您可以使用组合和链接字段控制子表单的内容:

combo link

组合链接

回答by Tahir

I had the same error. What I missing was the double quotes around a string. This error is a bit misleading. Check the syntax etc and you will find the issue was related to comma or double quotes etc.

我有同样的错误。我缺少的是字符串周围的双引号。这个错误有点误导。检查语法等,您会发现问题与逗号或双引号等有关。

回答by rob

I have just fixed this error. I was referencing the subform's source object, rather than its name given in the form properties.

我刚刚修复了这个错误。我引用的是子表单的源对象,而不是表单属性中给出的名称。