我使用Excel 2007作为Access 2007数据库的前端。工作流程是分析人员使用Excel中的表单将数据提交给DB,该数据库将存储并保存以供日后使用。我使用的是Microsoft ActiveX Data Objects 2.8 Library'将记录添加到数据库。
我使用" INSERT INTO"将所有字段添加到数据库查询,并没有问题。添加这些字段后,我想将文件添加到'附件' DB中的字段。我将用户计算机上的文件路径存储为表单上的变量。我到目前为止提出的代码是:
Private Sub addNewAttachment(id As String)
Dim sSql As String
Dim conn As ADODB.Connection 'connection
Dim rst As ADODB.Recordset 'recordset returned
'select the record with the id provided
sSql = "Select * from submitted_issues where ID = '" & id & "'"
Dim MyConn As String 'Location of DB
'DB location
MyConn = "\\path\to\db.accdb"
Debug.Print sSql
'open connection
Set conn = New ADODB.Connection
With conn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.Open MyConn
End With
'get recordset
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient
rst.Open Source:=sSql, ActiveConnection:=conn, CursorType:=adOpenForwardOnly, LockType:=adLockOptimistic, Options:=adCmdText
'The following lines do NOT work.
Call addAttachment(rst, "Files", frmIssueSubmission.txtAttachment.Value)
rst.Update
Set rst.ActiveConnection = Nothing
conn.Close
End Sub
最后4行不起作用。有没有人对如何在“附件”中添加附件有任何建议? Access中的数据类型字段?