2016-03-01 42 views
0

有以下代码“没有给定值”:错误在SQL条款

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 

开放引发错误

“没有一个或多个参数的给定值”

如果我删除它运行的where子句。该文件的Master_ID字段是双倍的,所以我将文本框的值转换为double,似乎应该起作用。在即时窗口MasterIDin和CDbl(Me!scanTxtBox.Value)具有相同的值。 我必须错过一些东西。

感谢

+1

我猜'MasterIDIn'应该是一个值,不能在字符串中传递。 –

+0

这看起来是否正确? [范围卡大师梅勒] .Master_ID = MasterIDIn –

回答

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 
+0

得到它,,非常感谢 – jpl458