Its in a standard module, basically a form button directs to a procedure in this standard module called "TempUpload", this then steps through a bunch of procedures performing different things.
Here's the full code:
Code:
Option Compare Database
Sub TempUpload()
Call FormattExcel
Call DeleteTemp
Call RunImport
Call LogUsage
MsgBox "Daily Import has been successfully complete", vbInformation, "Import Complete"
End Sub
Sub FormattExcel()
SelectFile:
Set f = Application.FileDialog(1)
With f
.AllowMultiSelect = False
.Title = "Please select daily upload from NFE"
.Show
For i = 1 To .SelectedItems.Count
filepath = .SelectedItems(i)
Next i
End With
If filepath = vbNullString Then
Answer = MsgBox("Do you want to select daily upload file again?", vbYesNo, "No Upload File Selected!")
If Answer = vbYes Then
GoTo SelectFile
Else
Exit Sub
End If
Else
End If
Set objExcel = CreateObject("Excel.Application")
With objExcel
.Workbooks.Open filepath
file = Right(filepath, Len(filepath) - InStrRev(filepath, "\"))
.Workbooks(file).Sheets(1).Range("G:H,K:K").Delete
Lastrow = .Workbooks(file).Sheets(1).Range("A" & Rows.Count).End(xlUp).Row
.Workbooks(file).Sheets(1).Range("F2:F" & Lastrow).NumberFormat = "dd/mm/yyyy"
For Each rgCell In .Workbooks(file).Sheets(1).Range("F2:F" & Lastrow).Cells
DateSplit = Split(Left(rgCell, 10), ".", 3)
rgCell.Value = DateSerial(DateSplit(2), DateSplit(1), DateSplit(0))
Next rgCell
For Each rgCell In .Workbooks(file).Sheets(1).Range("I2:I" & Lastrow).Cells
If rgCell.Value = "X" Then
rgCell.Value = -1
Else
rgCell.Value = 0
End If
Next rgCell
.Application.DisplayAlerts = False
.Workbooks(file).SaveAs "C:\Users\tbaker\Desktop\Merge\FB DB Saves\ImportTemp.xls", 56
.Workbooks("ImportTemp.xls").Close False
.Quit
End With
Set objExcel = Nothing
End Sub
Sub DeleteTemp()
If ifTableExists("tbl_Import") Then
DoCmd.DeleteObject acTable, "tbl_Import"
Else
End If
DoEvents
End Sub
Sub RunImport()
DoCmd.RunSavedImportExport "Import-ImportTemp"
CurrentDb.Execute "Update Query"
DoEvents
CurrentDb.Execute "Add Query"
DoEvents
End Sub
Sub LogUsage()
Set objFSO = CreateObject("Scripting.FileSystemObject")
outFile = "N:\National Share Drive\Excel Tools\VBA Tools\Counters\FB DB.txt"
Set objFile = objFSO.OpenTextFile(outFile, 8, True, 0)
objFile.WriteLine "1"
objFile.Close
End Sub
Public Function ifTableExists(tblName As String) As Boolean
ifTableExists = False
If DCount("[Name]", "MSysObjects", "[Name] = '" & tblName & "'") = 1 Then
ifTableExists = True
End If
End Function
Um I havent declared objExcel, maybe it is as simple as doing that, I have only set it on this line:
Code:
Set objExcel = CreateObject("Excel.Application")
Might try that now