Need to edge out the competition for your dream job? Train for certifications today.
Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
Private Sub cmdRun_Click()
''' requires reference to Microsoft Scripting library
Dim FSO As New FileSystemObject
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim rs As DAO.Recordset
Dim sBEPath As String
Dim sBEFile As String
Dim SourceFile As String
Dim TargetFile As String
Dim appExcel As Excel.Application 'Excel Object
Dim wbkNew As Excel.Workbook 'Workbook Object
Dim wksNew As Excel.Worksheet 'Sheet Object
Dim wbkTemplate As Excel.Workbook 'Workbook Object for Template
On Error GoTo ErrProc
Set db = CurrentDb()
Set qd = db.QueryDefs!qNamedRanges_Dashboard
'''' sBEPath = Mid(Me.txtFile, 1, InStrRev(Me.txtFile, "\"))
sBEPath = Me.txtPath
SourceFile = Mid(Me.txtFile, InStrRev(Me.txtFile, "\") + 1)
If Left(SourceFile, 9) = "Template_" Then 'remove "template_" from beginning if it is there
sBEFile = Mid(SourceFile, 10)
sBEFile = SourceFile
sBEFile = Left(sBEFile, InStrRev(sBEFile, ".") - 1) 'remove file extension
TargetFile = sBEPath & sBEFile & "ProdID_" & Me.cboProductionID & "_" & Format(Now(), "yyyymmdd_hhnnss") & ".xlsx" 'format new file name
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile SourceFile, TargetFile, True
Set rs = qd.OpenRecordset(dbOpenDynaset, dbSeeChanges)
Do Until rs.EOF
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, rs!QueryName, TargetFile, 0, rs!NamedRange
Set appExcel = New Excel.Application
Set wbkNew = appExcel.Workbooks.Open(TargetFile)
Set wksNew = appExcel.Worksheets("QueuePerformance")
.Range("C3").Value = Me.cboProductionID
.Range("B2").Value = Date
.Range("C2").Value = Format(Now(), "hh:mm")
appExcel.Visible = True
Me.txtOutputFileName = TargetFile
MsgBox "Export Complete", vbOKOnly
Select Case Err.Number
MsgBox Err.Number & "--" & Err.Description & "--"
MsgBox "Please select the template file.", vbOKOnly
MsgBox Err.Number & "--" & Err.Description, vbOKOnly
Open in new window
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment