私は過去数時間にわたり研究しており、これに対する解決策を見つけることはできませんでした。私がしたいのは、ユーザーがExcelからユーザーフォームを記入してAccessにデータを提出させることですが、フィールドの1つには本質的に添付ファイルであるスクリーンショットが必要です。私は2組のコード(DAOとADODB)を試しています。 ADODB接続を使用して簡単にAccessに他のデータ型を送信できますが、添付はできません。以下は私の2つのコードです:Excel VBAを使用してアクセスDBに添付ファイルを追加
Private Sub cmdSave_Click()
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
.AllowMultiSelect = False
.Title = "Please select file to attach"
If .Show = True Then
SelectFile = .SelectedItems(1)
Else
Exit Sub
End If
End With
Set fd = Nothing
Dim NewCon As DAO.Database
Dim RS As DAO.Recordset
Dim strFileName As String
Dim wrkAcc As Workspace
Set NewCon = OpenDatabase("C:\Users\my.user\Documents\Database1.accdb")
Set RS = OpenRecordset("REPORTS", dbOpenTable)
RS.Edit
RS.Fields("NAME").Value = Application.UserName
RS.Fields("DATE_REPORT").Value = Date
RS.Fields("CLAIM_TYPE").Value = "Fielda"
RS.Fields("CLIENT_NAME").Value = "Fieldb"
RS.Fields("ISSUE").Value = "Fieldc"
RS.Fields("REPORT_NUMBERS").Value = "Fieldd"
'RS.Fields("ATTACHMENTS"). (this is where I want to place the attachment)
RS.Fields("LOG_TIME").Value = Now
RS.Close
NewCon.Close
End Sub
これは、ADODBです:
Private Sub Image1_Click()
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
.AllowMultiSelect = False
.Title = "Please select file to attach"
If .Show = True Then
SelectFile = .SelectedItems(1)
Else
Exit Sub
End If
End With
Set fd = Nothing
Dim NewCon As ADODB.Connection
Set NewCon = New ADODB.Connection
Dim Recordset As ADODB.Recordset
Set Recordset = New ADODB.Recordset
NewCon.Open "Provider=Microsoft.ace.oledb.12.0;Data Source=C:\Users\my.user\Documents\Database1.accdb"
Recordset.Open "REPORTS", NewCon, adOpenDynamic, adLockOptimistic
Recordset.AddNew
Recordset.Fields(1).Value = Application.UserName
Recordset.Fields(2).Value = Date
Recordset.Fields(3).Value = "Fielda"
Recordset.Fields(4).Value = "Fieldb"
Recordset.Fields(5).Value = "Fieldc"
Recordset.Fields(6).Value = "Fieldd"
' Recordset.Fields(6) (this is where I want to place the attachment)
Recordset.Fields(8).Value = Now
Recordset.Update
Recordset.Close
NewCon.Close
End Sub
てみグーグル: "Accessデータベースの挿入画像VBA" – Sorceri
@Sorceri君場合欺瞞をして、そのように印を付ける。そうでなければ、私たちはここでもそれを持つことができると思います。私が見つけることができる最も近い詐欺師は[この1つ](https://stackoverflow.com/questions/18237180/add-view-attachments-using-ms-access-vba)でしたが、関連するコードはリンクされておりリンクは死んでいます。 –
@ErikvonAsmuthの3番目のリンクダウンが解決策でしたが、ポイントは10秒で見つけられれば難しいでしょう。 – Sorceri