标准表达式二进制到整数VBA中的数据类型不匹配

时间:2021-09-15 15:37:42

I'm writing an Excel Macro which works with an existing Access DB. Several of the queries I run will require input from the user as to which users they remove from a table, but seeing as the number will be the same each time I'd rather capture it once at the beginning of the macro and use that variable in my SQL statements. The number is for a quarter number of the year. So it'll either be 1,2,3 or 4 I can capture that from the user ok, but when I try to use the variable in an SQL statement I get the "Data Type Mismatch in Criteria error"

我正在编写一个Excel宏,它与现有的Access DB一起工作。的几个查询我运行需要来自用户的输入,用户删除从表,但每次看到数量将是相同的我宁愿捕获一次初的宏观和在SQL语句中使用该变量。这个数字是今年的四分之一。它可以是1 2 3 4我可以从用户那里获取它好的,但是当我尝试在SQL语句中使用变量时我得到了"标准错误数据类型不匹配"

Here is what I'm trying:

以下是我正在尝试的:

Dim Qrtnum As Integer

Qrtnum = Application.InputBox("Enter Quarter to Sample")

sql1 = "DELETE SampledEmailAddressesByQuarter.*, SampledEmailAddressesByQuarter.Quarter FROM SampledEmailAddressesByQuarter WHERE SampledEmailAddressesByQuarter.Quarter = "

appAccess.DoCmd.RunSQL sql1 & Qrtnum

Now in the table in my database the data type is listed as "Binary" and I'm trying to pass an Int variable into my SQL, could this be the problem? Or is the fact I have an Int concatenated with my SQL String?

在我的数据库中,数据类型被列为"二进制"我试图将一个Int变量传递到SQL中,这是问题吗?或者我的SQL字符串连接了一个Int类型?

Any help would be appreciated.

如有任何帮助,我们将不胜感激。

1 个解决方案

#1


1  

Bit of a cop out answer, but the credit should go to @HansUp. In the end I converted the data type of the field to number and managed to copy in all the data after. My code works fine now it's not trying to deal with a Binary data type. Still interested to know how I'd deal with this though. Thanks for all the help.

这个回答有点露骨,但应该归功于@HansUp。最后,我将字段的数据类型转换为number,并设法在后面复制所有数据。我的代码现在运行得很好,它不需要处理二进制数据类型。我还是很想知道我该怎么处理这个问题。谢谢你的帮助。

#1


1  

Bit of a cop out answer, but the credit should go to @HansUp. In the end I converted the data type of the field to number and managed to copy in all the data after. My code works fine now it's not trying to deal with a Binary data type. Still interested to know how I'd deal with this though. Thanks for all the help.

这个回答有点露骨,但应该归功于@HansUp。最后,我将字段的数据类型转换为number,并设法在后面复制所有数据。我的代码现在运行得很好,它不需要处理二进制数据类型。我还是很想知道我该怎么处理这个问题。谢谢你的帮助。