简体   繁体   中英

“No value given” error in where clause of sql

Have the following code:

    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

The open throws the error

"No value given for one or more of the parameters"

If I remove the where clause it runs. The Master_ID field on the file is double so I convert the textbox value to double and seems that should work. In the immediate window MasterIDin and CDbl(Me!scanTxtBox.Value) have the same values. I must be missing something.

Thanks

You need to dynamically create the string to allow MasterIDIn to take it's value within the VBA code. At the moment you are actually looking for the 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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