|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 木易禹 于 2012-3-12 09:57 编辑
下面的代码是需要将excel表中N9等几个指定位置的单元格数据添加到数据库RC表中的PROCESS等字段去,麻烦高手看一下,哪里有错误啊
Private Sub CommandButton1_Click()
Dim SQL As String
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cnn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cnn.Open "provider=Microsoft.jet.OLEDB.4.0;data source=" & ThisWorkbook.Path & "\分片单数据库.mdb"
If Range("N9 ").Value = " " Or Range("F9 ").Value = " " Or Range("B9 ").Value = " " Or Range("C5 ").Value = " " Or Range("B10 ").Value = " " Or Range("AI10").Value = " " Then
MsgBox ("请输入数据 ")
ElseIf Trim(Range("n9").Value) = " " Or Trim(Range("f9").Value) = " " Or Trim(Range("b9").Value) = " " Or Trim(Range("c5").Value) = " " Or Trim(Range("b10").Value) = " " Or Trim(Range("ai10").Value) = " " Then MsgBox ("数据不能为空")
Else
SQL = "INSERT INTO [RC] ([Process],[Product],[LotID],[RCNo],[Comment],[Owner]) values ( ' " & Trim(Range("n9 ").Value) & " ', ' " & Trim(Range("f9 ").Value) & " ', ' " & Trim(Range("b9 ").Value) & " ', ' " & Trim(Range("c5 ").Value) & " ',' " & Trim(Range("b10 ").Value) & " ',' " & Trim(Range("ai10 ").Value) & " ') ; "
cnn.Execute (SQL)
'MsgBox ("insert succeed ")
cnn.Close
End If
End Sub
|
|