What is the error?
All I did was replace the button code and run it. Did not have to change anything else. The following will allow user to select source file path with the file dialog. Get this to work as is before trying more customization.
Code:
Dim dbs As DAO.Database
Dim rstSource As DAO.Recordset
Dim rstSourceChild As DAO.Recordset
Dim rstDest As DAO.Recordset
Dim rstDestChild As DAO.Recordset
Dim strSql As String, fd As FileDialog
Dim strFilePath As String, strExtract As String
Set fd = FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = False
.Filters.Add "Access Files", "*.mdb;*.accdb", 1
.InitialFileName = CurrentProject.Path
If .Show Then strExtract = .SelectedItems(1)
End With
If strExtract <> "" Then
If MsgBox("REWRITE?", vbYesNo + vbQuestion) = vbYes Then
CurrentDb.Execute "DELETE FROM asli"
End If
CurrentDb.Execute "INSERT INTO asli([from], [to], describtion, [time]) " & _
"SELECT [from], [to], describtion, [time] FROM " & strExtract & ".asli"
Set dbs = OpenDatabase(strExtract)
Set rstSource = dbs.OpenRecordset("SELECT * FROM asli;", dbOpenDynaset)
While Not rstSource.EOF
Set rstSourceChild = rstSource.Fields("attach").Value
If Not rstSourceChild.EOF Then
Set rstDest = CurrentDb.OpenRecordset("SELECT * FROM asli WHERE from='" & rstSource![from] & _
"' AND to='" & rstSource!to & _
"' AND describtion='" & rstSource!describtion & _
"' AND time=" & rstSource!Time, dbOpenDynaset)
Set rstDestChild = rstDest.Fields("attach").Value
rstDest.Edit
While Not rstSourceChild.EOF
'save attachment from Portable to folder
strFilePath = "C:\Temp\" & rstSourceChild.Fields("FileName")
If Dir(strFilePath) <> "" Then VBA.Kill strFilePath
rstSourceChild.Fields("FileData").SaveToFile strFilePath
'save attachment from folder to Main
rstDestChild.AddNew
rstDestChild.Fields("FileData").LoadFromFile strFilePath ' store the file's contents in the new row.
rstDestChild.Update ' commit the new row.
rstSourceChild.MoveNext
Wend
rstSourceChild.Close
rstDestChild.Close
rstDest.Update
rstDest.Close
End If
rstSource.MoveNext
Wend
End If