ili_sophia
Registered User.
- Local time
- Today, 12:12
- Joined
- Aug 23, 2017
- Messages
- 40
Hi There,
I have an access userform that allows the users to import in their excel worksheet and it will append the data to the tables.
However, now I am facing the problem of updating the table.
In the case where the users have already uploaded the worksheets into access but suddenly finds an error in some of the fields of excel worksheet, they would need to make changes to the data.
Is there a way to allow the users to reimport the excel worksheet and it will update the access table?
can it match the excel and access table through the primary key and update the changes in the field?
My module code:
Option Compare Database
Option Explicit
Public Sub ImportExcelSpreadsheet(fileName As String, tableName As String)
On Error GoTo BadFormat
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, tableName, fileName, True
Exit Sub
BadFormat:
MsgBox "The file you tried to import was not an Excel Spreadsheet."
End Sub
My browse button on the userform:
Private Sub btnSettingBrowse_Click()
Dim diag As Office.FileDialog
Dim item As Variant
Set diag = Application.FileDialog(msoFileDialogFilePicker)
diag.AllowMultiSelect = False
diag.Title = "Please select an Excel Spreadsheet"
diag.Filters.Clear
diag.Filters.Add "Excel Spreadsheet", "*.xls, *.xlsx"
If diag.Show Then
For Each item In diag.SelectedItems
Me.SettingFileName = item
Next
End If
End Sub
My import excel worksheet on the userform:
Private Sub btnSettingImportSpreadsheet_Click()
On Error GoTo ErrorMessage
Dim FSO As New FileSystemObject
If Nz(Me.SettingFileName, "") = "" Then
MsgBox "Please Select a File"
Exit Sub
End If
If FSO.FileExists(Nz(Me.SettingFileName, "")) Then
If MsgBox("Do you want to import this file?", vbYesNo) = vbYes Then
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "Setting", Me.SettingFileName, True, SettingComboBox & "!"
MsgBox "File Imported"
ErrorMessage:
If Err = 2391 Then
MsgBox "Sorry, you have selected the wrong file to import. Please select the correct file. Thank You."
Exit Sub
End If
End If
End If
DoCmd.SetWarnings False
End Sub
I have an access userform that allows the users to import in their excel worksheet and it will append the data to the tables.
However, now I am facing the problem of updating the table.
In the case where the users have already uploaded the worksheets into access but suddenly finds an error in some of the fields of excel worksheet, they would need to make changes to the data.
Is there a way to allow the users to reimport the excel worksheet and it will update the access table?
can it match the excel and access table through the primary key and update the changes in the field?
My module code:
Option Compare Database
Option Explicit
Public Sub ImportExcelSpreadsheet(fileName As String, tableName As String)
On Error GoTo BadFormat
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, tableName, fileName, True
Exit Sub
BadFormat:
MsgBox "The file you tried to import was not an Excel Spreadsheet."
End Sub
My browse button on the userform:
Private Sub btnSettingBrowse_Click()
Dim diag As Office.FileDialog
Dim item As Variant
Set diag = Application.FileDialog(msoFileDialogFilePicker)
diag.AllowMultiSelect = False
diag.Title = "Please select an Excel Spreadsheet"
diag.Filters.Clear
diag.Filters.Add "Excel Spreadsheet", "*.xls, *.xlsx"
If diag.Show Then
For Each item In diag.SelectedItems
Me.SettingFileName = item
Next
End If
End Sub
My import excel worksheet on the userform:
Private Sub btnSettingImportSpreadsheet_Click()
On Error GoTo ErrorMessage
Dim FSO As New FileSystemObject
If Nz(Me.SettingFileName, "") = "" Then
MsgBox "Please Select a File"
Exit Sub
End If
If FSO.FileExists(Nz(Me.SettingFileName, "")) Then
If MsgBox("Do you want to import this file?", vbYesNo) = vbYes Then
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "Setting", Me.SettingFileName, True, SettingComboBox & "!"
MsgBox "File Imported"
ErrorMessage:
If Err = 2391 Then
MsgBox "Sorry, you have selected the wrong file to import. Please select the correct file. Thank You."
Exit Sub
End If
End If
End If
DoCmd.SetWarnings False
End Sub