简体   繁体   English

访问DLookup数据不匹配错误

[英]Access DLookup Data Mismatch error

I need help. 我需要帮助。 I'm using Access 2007 at my work. 我在工作中使用Access 2007。

I keep getting the Run-time error 3464: Data type mistmatch in criteria expression. 我不断收到运行时错误3464:条件表达式中的数据类型mistmatch。 This was working fine and then all of the sudden it wasn't. 一切正常,然后突然变坏了。

I've made some adjustments to my original code but I'm still getting the error. 我已经对原始代码进行了一些调整,但是仍然出现错误。

Please help, this is very frustrating! 请帮助,这非常令人沮丧!

Private Sub Loan__AfterUpdate()
Me.Refresh
Dim GetInfoCriteria As String
GetInfoCriteria = "[ACCOUNT_NUMBER] = '" & Screen.ActiveForm.Recordset.Fields("Loan#").Value & "'"
Debug.Print GetInfoCriteria

[Loan#] = DLookup("[ACCOUNT_NUMBER]", "tbl_GetInfo", GetInfoCriteria)

EDIT 编辑

Here is my old code that worked for a while: 这是我的旧代码工作了一段时间:

[Loan#] = DLookup("[ACCOUNT_NUMBER]", "tbl_GetInfo", "[ACCOUNT_NUMBER] = '" & Screen.ActiveForm.Recordset.Fields("Loan#").Value & "'")

I have two table, tbl_GetInfo and tbl_CE. 我有两个表,tbl_GetInfo和tbl_CE。 tbl_CE is populated by the user working with a form frm_CE. 用户使用表格frm_CE填充tbl_CE。 When the user enters the loan # into frm_CE, I want it to use Dlookup to get this and other information from tbl_GetInfo and put that into tbl_CE. 当用户将贷款#输入frm_CE时,我希望它使用Dlookup从tbl_GetInfo获取此信息和其他信息,并将其放入tbl_CE。 I chose this one field as an example but there are others that it will populate in the same Sub, this is the full example 我选择了此字段作为示例,但其他字段将填充在同一Sub中,这是完整的示例

Dim GetInfoCriteria As String
GetInfoCriteria = "[ACCOUNT_NUMBER] = '" & Screen.ActiveForm.Recordset.Fields("SLSLoan#").Value & "'"
Debug.Print GetInfoCriteria
'
[Loan#] = DLookup("[ACCOUNT_NUMBER]", "tbl_GetInfo", GetInfoCriteria)
[Inv] = DLookup("[INVESTOR_CODE]", "tbl_GetInfo", GetInfoCriteria)
[Name] = DLookup("[BORROWER_PRIMARY_NAME]", "tbl_GetInfo", GetInfoCriteria)
[Status] = DLookup("[LOAN_OTS_OVERALL_STATUS]", "tbl_GetInfo", GetInfoCriteria)

Sorry I hope that helps 对不起,希望对您有所帮助

So I got it to work by writing it like this: 因此,我通过像这样编写它来使其工作:

[Loan#] = DLookup("[ACCOUNT_NUMBER]", "tbl_GetInfo", "[ACCOUNT_NUMBER] = " & Screen.ActiveForm.Recordset.Fields("Loan#").Value)

I think it was that the Loan# is a number so even if the other fields are text or number, it needs to be written like a number. 我认为这是贷款编号是数字,所以即使其他字段是文本或数字,也需要像数字一样书写。 Anyway, thanks and sorry it wasn't a very easy to describe problem. 无论如何,谢谢和抱歉,这不是一个很容易描述的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM