拥有以下代码:
Dim MasterIDIn As Double 'Use in where clause
MasterIDIn = CDbl(Me!scanTxtBox.Value)
Dim RCMSql As String
RCMSql = "SELECT [Range Card Master Mailer].Master_ID," & _
"[Range Card Master Mailer].MaxOfDate_of_Transaction," & _
"[Range Card Master Mailer].FirstName," & _
"[Range Card Master Mailer].LastName," & _
"[Range Card Master Mailer].Email_Address," & _
"[Range Card Master Mailer].Address_Line_1," & _
"[Range Card Master Mailer].Phone_Number_1," & _
"[Range Card Master Mailer].Phone_Number_2," & _
"[Range Card Master Mailer].Date_Sent," & _
"[Range Card Master Mailer].CouponValue," & _
"[Range Card Master Mailer].RedeemDate," & _
"[Range Card Master Mailer].RedeemFlag " & _
"FROM [Range Card Master Mailer] " & _
"WHERE ((([Range Card Master Mailer].Master_ID)= MasterIDIn))"
RCMRs.Open RCMSql 'Fill the recordset
open会抛出错误
"没有给出一个或多个参数的值#34;
如果我删除它运行的where子句。文件上的Master_ID字段是双倍的,所以我将文本框值转换为double,看起来应该有效。在即时窗口中,MasterIDin和CDbl(Me!scanTxtBox.Value)具有相同的值。 我一定错过了什么。
由于
答案 0 :(得分:0)
您需要动态创建字符串以允许MasterIDIn
在VBA代码中获取其值。目前您正在寻找MasterID
'MasterIDIn'。
Dim RCMSql As String
RCMSql = "SELECT [Range Card Master Mailer].Master_ID," & _
"[Range Card Master Mailer].MaxOfDate_of_Transaction," & _
"[Range Card Master Mailer].FirstName," & _
"[Range Card Master Mailer].LastName," & _
"[Range Card Master Mailer].Email_Address," & _
"[Range Card Master Mailer].Address_Line_1," & _
"[Range Card Master Mailer].Phone_Number_1," & _
"[Range Card Master Mailer].Phone_Number_2," & _
"[Range Card Master Mailer].Date_Sent," & _
"[Range Card Master Mailer].CouponValue," & _
"[Range Card Master Mailer].RedeemDate," & _
"[Range Card Master Mailer].RedeemFlag " & _
"FROM [Range Card Master Mailer] " & _
"WHERE ((([Range Card Master Mailer].Master_ID)= " & MasterIDIn & "))"
RCMRs.Open RCMSql 'Fill the recordset