且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Excel VBA INSERT INTO语句中使用变量

更新时间:2023-01-19 17:16:30

为什么不使用日期/时间字段包括测试时间?

Why not make use of date/time field to include test time?

***格式化日期,假设b5是日期类型:

It is best to format dates, assuming that b5 is a date type:

testDate = Format(Range("b5").Value,"yyyy/mm/dd")

你最终会得到文字,但这并不重要。

You will end up with text, but this is not important.

stSQL1 = "INSERT INTO [Friction Tests] ([Runway Number], [Runway Test Side], " _
& "[Test Date], [Test Time], [1/3], [2/3], [3/3], [Average]) " _
& "VALUES ( " & rwyNumber  & ",#" &  testDate   & "#,#" & testTime   _
& "#," & rwySide1   & "," & firstThird1 _
& "," & secondThird1   & "," & thirdThird1 _
& "," & averageFriction1 & ")"

如果任何字段为文本,该值将必须由单引号括起来或者两个双引号,以与日期和时间相似的方式。

If any of the fields are text, the value will have to be surrounded by single quotes or two double quotes, in a similar way to date and time.

我强烈建议在字段(列)和表名中删除空格。

I strongly recommend getting rid of spaces in field (column) and table names.