我希望将SQL SERVER中的图像路径字段插入到vba代码访问的表中,但是它运行并发送运行时错误3075,整个字段插入成功,路径除外。
Dim sqlstr As String
Dim sqlstr1 As String
dim strSQL as string
Set rs = CreateObject("ADODB.Recordset")
rs.CursorType = adOpenDynamic
rs.LockType = adLockReadOnly
rs.ActiveConnection = db
DoCmd.SetWarnings False
DoCmd.RunSQL "delete from tb_brws"
DoCmd.SetWarnings True
rs.Open "SELECT [sno] [imgp] from books_tb where [sno] like '" & Me.sno_txt & "' ;"
rs.MoveFirst
Do
sqlstr = rs![sno]
sqlstr1 = rs1![imgp]
DoCmd.SetWarnings False
strSQL="insert into tb_brws (sno,imgp) values ('" & sqlstr & "', '" & sqlstr1 & "')"
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
rs.MoveNext
Loop While Not rs.EOF
Set rs = Nothing
答案 0 :(得分:0)
感谢您显示实际的SQL字符串 - 它非常有用,因为它显示字符串中有一个引号(01-08-2016' 123.pdf)。 Access认为这是一个分隔符(无论你是否用双引号括起来)。 请使用以下代码(我已经过测试,它的工作正常)。
DoCmd.SetWarnings False
' this will change any ' characters to '' which will allow the SQL to run.
sqlstr1 = Replace(sqlstr1, "'", "''") ' REPLACE SINGLE QUOTE
strSQL = "insert into tb_brws (sno,imgp) values ('" & sqlstr & "', '" & sqlstr1 & "')"
Debug.Print "MySQL: " & strSQL
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True