H
headly
vba to open excel, transfer to spreadsheet, run an autoopen macro, and return
to access causes access 2007 on windows Xp to hang/crash with a white screen
and not responding in the title bar; Any idea where/why it is wrong? TIA
Private Sub Button___Social_Policy_Click()
'Get the path to the database
Dim vPath As Variant
vPath = Application.CurrentProject.Path
'Get the path to local user my documents folder
Dim vMyDocsPath As Variant
vMyDocsPath = Environ$("USERPROFILE") & "\My Documents\"
'If Directory exists, Mkdir causes an error - ignore it
On Error Resume Next
'Create a new folder inside my documents
MkDir vMyDocsPath & "\Staff Functional Reports\"
ChDir vMyDocsPath & "\Staff Functional Reports\"
'Before get the record date - test to see if a value was chosen
If Me.Record_Date___Social_Policy.Value Is Not Null Then
'Get the record date value - Used to name the file
Dim vRecordDate As Variant, vMonth As Variant, vDay As Variant, vYear As
Variant
vRecordDate = Me.Record_Date___Social_Policy.Value
'vRecordDate is not usable format i.e. 11/1/09; Need to convert
'to MMM-DD-YYYY format to use in filename
vMonth = Left(vRecordDate, InStr(1, vRecordDate, "/") - 1)
vYear = Right(vRecordDate, 4)
vDay = Mid(vRecordDate, InStr(1, vRecordDate, "/") + 1, Len(vRecordDate)
- Len(vYear) - Len(vMonth) - 2)
'run the query
DoCmd.OpenQuery ("Functional Report - Social Policy")
'Hide the form
Me.Visible = False
'Export to excel
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"Functional Report - Social Policy", "Functional Report - Social Policy
" & vMonth & "-" & vDay & "-" & vYear
'Start Excel and Open the file
Dim objXL As Object, x As Variant
Set objXL = CreateObject("Excel.Application")
With objXL.Application
.Visible = True
'Open the Workbook
.Workbooks.Open vMyDocsPath & "\Staff Functional Reports\" & _
"Functional Report - Social Policy " & vMonth & "-" & vDay & "-"
& vYear
'In Excel, use the database path, vpath to open the xl formatting
macro
.Workbooks.Open vPath & "\" & "VBA Development - Report Formatting -
DIST.xlsm"
.ActiveWorkbook.RunAutoMacros
End With
'Wait 30 seconds, then force close the VBA Development - Report
Formatting - DIST.xlsm macro
Dim vPauseTime As Variant, vStartTime As Variant
vPauseTime = 30
vStartTime = Timer
Do While Time < vStartTime + vPauseTime
'Do Nothing, just wait
Loop
'Now force close the XL Macro workbook for other users
With objXL.appliction
.Workbooks.Close vPath & "\" & "VBA Development - Report Formatting
- DIST.xlsm"
End With
Set objXL = Nothing
'Show the form
Me.Visible = True
ElseIf Me.Record_Date___Social_Policy.Value = "" Or
Me.Record_Date___Social_Policy.Value Is Null Then
MsgBox "Please choose a record date before running the report . . .",
vbInformation + vbOKOnly, "Date Required"
Me.Record_Date___Social_Policy.SetFocus
Exit Sub
End If
to access causes access 2007 on windows Xp to hang/crash with a white screen
and not responding in the title bar; Any idea where/why it is wrong? TIA
Private Sub Button___Social_Policy_Click()
'Get the path to the database
Dim vPath As Variant
vPath = Application.CurrentProject.Path
'Get the path to local user my documents folder
Dim vMyDocsPath As Variant
vMyDocsPath = Environ$("USERPROFILE") & "\My Documents\"
'If Directory exists, Mkdir causes an error - ignore it
On Error Resume Next
'Create a new folder inside my documents
MkDir vMyDocsPath & "\Staff Functional Reports\"
ChDir vMyDocsPath & "\Staff Functional Reports\"
'Before get the record date - test to see if a value was chosen
If Me.Record_Date___Social_Policy.Value Is Not Null Then
'Get the record date value - Used to name the file
Dim vRecordDate As Variant, vMonth As Variant, vDay As Variant, vYear As
Variant
vRecordDate = Me.Record_Date___Social_Policy.Value
'vRecordDate is not usable format i.e. 11/1/09; Need to convert
'to MMM-DD-YYYY format to use in filename
vMonth = Left(vRecordDate, InStr(1, vRecordDate, "/") - 1)
vYear = Right(vRecordDate, 4)
vDay = Mid(vRecordDate, InStr(1, vRecordDate, "/") + 1, Len(vRecordDate)
- Len(vYear) - Len(vMonth) - 2)
'run the query
DoCmd.OpenQuery ("Functional Report - Social Policy")
'Hide the form
Me.Visible = False
'Export to excel
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"Functional Report - Social Policy", "Functional Report - Social Policy
" & vMonth & "-" & vDay & "-" & vYear
'Start Excel and Open the file
Dim objXL As Object, x As Variant
Set objXL = CreateObject("Excel.Application")
With objXL.Application
.Visible = True
'Open the Workbook
.Workbooks.Open vMyDocsPath & "\Staff Functional Reports\" & _
"Functional Report - Social Policy " & vMonth & "-" & vDay & "-"
& vYear
'In Excel, use the database path, vpath to open the xl formatting
macro
.Workbooks.Open vPath & "\" & "VBA Development - Report Formatting -
DIST.xlsm"
.ActiveWorkbook.RunAutoMacros
End With
'Wait 30 seconds, then force close the VBA Development - Report
Formatting - DIST.xlsm macro
Dim vPauseTime As Variant, vStartTime As Variant
vPauseTime = 30
vStartTime = Timer
Do While Time < vStartTime + vPauseTime
'Do Nothing, just wait
Loop
'Now force close the XL Macro workbook for other users
With objXL.appliction
.Workbooks.Close vPath & "\" & "VBA Development - Report Formatting
- DIST.xlsm"
End With
Set objXL = Nothing
'Show the form
Me.Visible = True
ElseIf Me.Record_Date___Social_Policy.Value = "" Or
Me.Record_Date___Social_Policy.Value Is Null Then
MsgBox "Please choose a record date before running the report . . .",
vbInformation + vbOKOnly, "Date Required"
Me.Record_Date___Social_Policy.SetFocus
Exit Sub
End If