Hi all,
I am trying to upload excel file and then run bunch of queries to update few tables based on uploaded file. I want to have a sub that calls function(to upload excel) with two vars supplied, and function in turn returns Boolean value back to sub. So the sub can use the boolean value to call or not call other sub which runs queries. I am having an issue writing this. Below is what I so far and it is causing compile error at If(updateUsers.importExcel....)
Sub Calling a function and passing file name and table name
Funtion:
I am trying to upload excel file and then run bunch of queries to update few tables based on uploaded file. I want to have a sub that calls function(to upload excel) with two vars supplied, and function in turn returns Boolean value back to sub. So the sub can use the boolean value to call or not call other sub which runs queries. I am having an issue writing this. Below is what I so far and it is causing compile error at If(updateUsers.importExcel....)
Sub Calling a function and passing file name and table name
Code:
Private Sub BtnImport_Click()
Dim fso As New FileSystemObject
If Nz(Me.TxtFileName, "") = "" Then 'Checking file path is entered
MsgBox "Please select the file!"
Exit Sub
End If
If fso.FileExists(Me.TxtFileName) Then
If (UpdateUsers.ImportExcel Me.TxtFileName, "ActiveList" ) = True then 'Calling funtion to upload AL to a table
Call Sync ' Running queries to upload ActiveList
End If
Else
MsgBox "File Not Found", vbInformation, "Incorrect File Location"
End If
End Sub
Funtion:
Code:
Public Function ImportExcel(fileName As String, tableName As String) As Boolean
On Error GoTo Problem
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, tableName, fileName, True
ImportExcel = True
Exit Function
Problem:
MsgBox "The file you tried to import was not an Excel spreadsheet. Please ensure that file is saved as .xls (97-2003)"
ImportExcel = False
End Function