M
MarkV
I'm using Access and Excel 2007
Command button from Access form calls event sub procedure
Sub procedureI copies master excel file into scratch excel file. Sub
procedure then calls function that adds customer info to scratch excel file
then returns to sub procedure. Calling sub procedure then opens excel with
scratch file with new customer info.
All works okay except when sub procedure opens excel with edited scratch
file, the excel program shows a completely white screen (no cells). When I
set excel to view full screen, the workbook appears and has correct info.
When I click normal view it appears normal as well.
What causes Excel to open with "white screen"
I think I correctly closed excel after editing in sub procedure, but if I
add a stop in the code after the appExcel.quit command the task manager shows
excel running.
Any suggestions?
thanks Mark
---------------------------------------------------------
Private Sub cmbExportAutomation_Click()
On Error GoTo err_Handler
MsgBox ExportRequest, vbInformation, "Finished"
Application.FollowHyperlink CurrentProject.Path & "\New_Quote.xls"
exit_Here:
Exit Sub
err_Handler:
MsgBox Err.Description, vbCritical, "Error"
Resume exit_Here
End Sub
'-----------------------------------------------------------------
Public Function ExportRequest() As String
On Error GoTo err_Handler
'-- Excel object variables
Dim appExcel As Excel.Application
Dim wbk As Excel.Workbook
Dim wks As Excel.Worksheet
Dim sTemplate As String
Dim sOutput As String
'---- Customer Strings
Dim sCustomerName As String
Dim sCompanyName As String
Dim sAddress As String
Dim sCityStateZip As String
Dim sPhone As String
Dim sEmail As String
Dim iRow As Integer
Dim iCol As Integer
Const cTabTwo As Byte = 1
Const cStartRow As Byte = 16
Const cStartColumn As Byte = 2
'--- First Test, Set customer values here
' Later read from database
sCustomerName = " Sample Customer Name"
sCompanyName = "We Buy Optics Inc"
sAddress = "1212 My Street, Suite 1"
sCityStateZip = "Los Angles, CA 99999"
sPhone = "203-555-1212"
sEmail = "(e-mail address removed)"
'--- set to break on all errors
Application.SetOption "Error Trapping", 0
'-- Start with a clean file built from the template file
sTemplate = CurrentProject.Path & "\MasterQuoteTemplate.xls"
sOutput = CurrentProject.Path & "\New_Quote.xls"
If Dir(sOutput) <> "" Then Kill sOutput
FileCopy sTemplate, sOutput
'--- Create the Excel Applicaiton, Workbook and Worksheet and Database
object
Set appExcel = Excel.Application
Set wbk = appExcel.Workbooks.Open(sOutput)
Set wks = appExcel.Worksheets(cTabTwo)
'--- For this template, the data must be placed on the row, column.
' (these values are set to constants for easy future modifications)
iCol = cStartColumn
iRow = cStartRow
Stop
'-- Insert values here
wks.Cells(iRow, iCol) = sCustomerName
iRow = iRow + 1
wks.Cells(iRow, iCol) = sCompanyName
iRow = iRow + 1
wks.Cells(iRow, iCol) = sAddress
iRow = iRow + 1
wks.Cells(iRow, iCol) = sCityStateZip
iRow = iRow + 1
wks.Cells(iRow, iCol) = sPhone
iRow = iRow + 1
wks.Cells(iRow, iCol) = sEmail
'-- Set Function value
ExportRequest = "Request complete"
'-- Save file
wbk.Save
exit_Here:
' Cleanup all objects (resume next on errors)
On Error Resume Next
Set wks = Nothing
Set wbk = Nothing
appExcel.Quit
Set appExcel = Nothing
Stop
Exit Function
err_Handler:
ExportRequest = Err.Description
'Me.lblMsg.Caption = Err.Description
Resume exit_Here
End Function
Command button from Access form calls event sub procedure
Sub procedureI copies master excel file into scratch excel file. Sub
procedure then calls function that adds customer info to scratch excel file
then returns to sub procedure. Calling sub procedure then opens excel with
scratch file with new customer info.
All works okay except when sub procedure opens excel with edited scratch
file, the excel program shows a completely white screen (no cells). When I
set excel to view full screen, the workbook appears and has correct info.
When I click normal view it appears normal as well.
What causes Excel to open with "white screen"
I think I correctly closed excel after editing in sub procedure, but if I
add a stop in the code after the appExcel.quit command the task manager shows
excel running.
Any suggestions?
thanks Mark
---------------------------------------------------------
Private Sub cmbExportAutomation_Click()
On Error GoTo err_Handler
MsgBox ExportRequest, vbInformation, "Finished"
Application.FollowHyperlink CurrentProject.Path & "\New_Quote.xls"
exit_Here:
Exit Sub
err_Handler:
MsgBox Err.Description, vbCritical, "Error"
Resume exit_Here
End Sub
'-----------------------------------------------------------------
Public Function ExportRequest() As String
On Error GoTo err_Handler
'-- Excel object variables
Dim appExcel As Excel.Application
Dim wbk As Excel.Workbook
Dim wks As Excel.Worksheet
Dim sTemplate As String
Dim sOutput As String
'---- Customer Strings
Dim sCustomerName As String
Dim sCompanyName As String
Dim sAddress As String
Dim sCityStateZip As String
Dim sPhone As String
Dim sEmail As String
Dim iRow As Integer
Dim iCol As Integer
Const cTabTwo As Byte = 1
Const cStartRow As Byte = 16
Const cStartColumn As Byte = 2
'--- First Test, Set customer values here
' Later read from database
sCustomerName = " Sample Customer Name"
sCompanyName = "We Buy Optics Inc"
sAddress = "1212 My Street, Suite 1"
sCityStateZip = "Los Angles, CA 99999"
sPhone = "203-555-1212"
sEmail = "(e-mail address removed)"
'--- set to break on all errors
Application.SetOption "Error Trapping", 0
'-- Start with a clean file built from the template file
sTemplate = CurrentProject.Path & "\MasterQuoteTemplate.xls"
sOutput = CurrentProject.Path & "\New_Quote.xls"
If Dir(sOutput) <> "" Then Kill sOutput
FileCopy sTemplate, sOutput
'--- Create the Excel Applicaiton, Workbook and Worksheet and Database
object
Set appExcel = Excel.Application
Set wbk = appExcel.Workbooks.Open(sOutput)
Set wks = appExcel.Worksheets(cTabTwo)
'--- For this template, the data must be placed on the row, column.
' (these values are set to constants for easy future modifications)
iCol = cStartColumn
iRow = cStartRow
Stop
'-- Insert values here
wks.Cells(iRow, iCol) = sCustomerName
iRow = iRow + 1
wks.Cells(iRow, iCol) = sCompanyName
iRow = iRow + 1
wks.Cells(iRow, iCol) = sAddress
iRow = iRow + 1
wks.Cells(iRow, iCol) = sCityStateZip
iRow = iRow + 1
wks.Cells(iRow, iCol) = sPhone
iRow = iRow + 1
wks.Cells(iRow, iCol) = sEmail
'-- Set Function value
ExportRequest = "Request complete"
'-- Save file
wbk.Save
exit_Here:
' Cleanup all objects (resume next on errors)
On Error Resume Next
Set wks = Nothing
Set wbk = Nothing
appExcel.Quit
Set appExcel = Nothing
Stop
Exit Function
err_Handler:
ExportRequest = Err.Description
'Me.lblMsg.Caption = Err.Description
Resume exit_Here
End Function