Public Sub CheckTable()
Dim fIsTableEmpty As Boolean
Dim db As Database
Dim rs As Recordset
Set db = DBEngine(0)(0)
Set rs = db.OpenRecordset("Scrap", dbOpenTable)
If rs.RecordCount = 0 Then
fIsTableEmpty = True
MsgBox "Nothing in the table, Please import Cognos report"
On Error GoTo Error_Handler
Dim fdg As FileDialog, vrtSelectedItem As Variant
Dim strSelectedFile As String
Set fdg = Application.FileDialog(msoFileDialogFilePicker)
With fdg
.Filters.Clear
.Filters.Add "Excel Files", "*.xls"
.Filters.Add "Excel 2007", "*.xlsx"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewDetails
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
strSelectedFile = vrtSelectedItem
Next vrtSelectedItem
Else
End If
' If Not IsEmpty(strSelectedFile) Then
If Len(Trim(strSelectedFile) & "") > 0 Then
Dim StrSQL As String
StrSQL = "Delete * from Scrap;"
DoCmd.SetWarnings False
DoCmd.RunSQL StrSQL
DoCmd.SetWarnings True
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "Scrap", strSelectedFile, True, , False
Else
DoCmd.OpenForm "FileNotSelected", acNormal, , , , , False
End If
End With
Set fd = Nothing
Exit_Procedure:
Exit Sub
|