2016-03-01 71 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