Guys, hi.
I have a vba code for transfering data from an excel file to access database.

My code is run using BeforeSave action. The cde is working fine, with one bug: it transfers only the data which were when excel file (*.xlsm) was open. It doesn't transfer
data which are changed after the opening of the excel file.


Here is code sample:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
Application.Calculate
a = MsgBox("Do you want to save data to the database?", vbYesNo)
If a = vbYes Then
Cancel = True
Call Export_KLPN_xls_u_bazu
End If

End Sub


Public Sub Export_KLPN_xls_u_bazu()
Dim oDB As New Access.Application

'Create Object to Link to the Access Databse
oDB.OpenCurrentDatabase "\\SERVER_LOCATION\baza_KLPN.accdb", False

'Import from Excel to Access
oDB.DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "table_name", ThisWorkbook.FullName, True, "sheet_name$A1:aC4"



'Close Access Application and quit
oDB.CloseCurrentDatabase
oDB.Quit
Set oDB = Nothing

MsgBox "Data saved to the database"
End Sub



Could you give me an advice?