我之前使用VBA插入到SQL表中,但它始终使用单元格中的值。我的表中有三列,我只需要添加一个静态值(所以没有单元格引用)。
我到目前为止的代码是:
stSQL = "INSERT INTO Client_Notes " & _
"(ID, Category, RefID, Name, Notes, Date_Loaded, Latest) " & _
" VALUES (" & _
"'" & 1 & "', " & _
"'" & 1 & "', " & _
"'" & Sheets("Missing").ActiveCell.Offset(0, -10).Value & "', " & _
"'" & Sheets("Missing").ActiveCell.Offset(0, -9).Value & "', " & _
"'" & Sheets("Details").ActiveCell.Value & "', " & _
"'" & Date & "', " & "'" & _
"'" & 1 & "'" & _
")"
我不断得到的错误是在尝试将1作为值插入时。我确信它是直截了当的,但我觉得我已经尝试了每个引号和逗号组合。
提前致谢
所以新代码现在看起来是这样的,我在这里得到了下标超出范围:
stSQL = "INSERT INTO Client_Notes " & _
"(ID, Category, RefID, Name, Notes, Date_Loaded, Latest) " & _
" VALUES (" & _
"1, " & _
"1, " & _
"'" & Sheets("Missing").Range("L" & i).Offset(0, -10).Value & "', " & _
"'" & Sheets("Missing").Range("L" & i).Offset(0, -9).Value & "', " & _
"'" & Sheets("Details").Range("L" & i).Value & "', " & _
"'" & Date & "', " & _
"1)"