I checked for few days how to do this and I'm getting close to the solution, but I still can't find how to do it.
- Back-end is MySQL and I have a table called Product with different fields, one of them being Datasheet (BLOB data type)
- Front-end is MS Access 2010, and connects to database through ODBC.
- I'm using mostly bound forms to add new records to the tables.
So far what I've got is a form where you input all the data for each field of Product table. At the end of it I have a "Attachment" field (made by wizard), I created an event:
Private Sub Attachment_Click() as String
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 Function
End If
End With
Set fd = Nothing
End Function
So this will return the path of the file.
Now, when I click the button Save of my form, I basically declare the form Me.Dirty So the fields are automatically updated to the database. But the attachment doesn't upload.
I checked: Add/view attachments using MS Access VBA. This is great, but I am missing how to specifically tell to MySQL by using VBA which row it should add the information to. I am thinking using the Form_AfterUpate() to do the rutine, so then I know that all the other fields have been already saved.