Export text bugs

B

B. Meincke

I have a button on the switchboard of an Access 2007 database that is
programmed to export the results of a query to an Excel '97-'03 workbook with
formatting. For the most part it works, but with a couple of bugs.

The first time it runs the coded formatting is applied without error and the
workbook is created. However, even though the field data is set to uppercase
in the query, in the resulting workbook the field data appears as it was
input into the underlying table (usually lowercase). ???

The real problem arises when the OnClick method executes for a second time.
I want this to result in deleting the exsisting file and then recreating it.
But for some reason, the script fails at the point where it should freeze row
1. ??????

Here is the code. Can anyone suggest why these things are happening?

Thanks in advance for any input.

******************************************************

Private Sub cmdExport_Click()

Dim objExcel As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlWS As Excel.Worksheet

Dim strFile As String
Dim strDest As String

Dim strMyDB As String

strMyDB = CurrentDb.Name
strPath = Left(strMyDB, LastInStr(strMyDB, "\"))
strFile = strPath & "This week's Open Houses.xls"

If Dir(strFile) <> "" Then
Kill strFile
End If

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9,
"qryOHLReview", strFile, True

Set objExcel = New Excel.Application
objExcel.Visible = True

Set xlWB = objExcel.Workbooks.Open(strFile)
Set xlWS = xlWB.ActiveSheet

With xlWS

.Range("A1:R1").Font.Bold = True
.Range("A1:R1").HorizontalAlignment = xlCenter
.Range("A1:R1").Font.ColorIndex = 2
.Range("A1:R1").Interior.ColorIndex = 1

.Range("A:R").HorizontalAlignment = xlLeft
.Range("E:E").NumberFormat = "$#,##0.00"
.Range("E:E").HorizontalAlignment = xlRight

'AutoFit the columns
.Range("A:R").Columns.AutoFit

.Range("2:2").Select
End With

With ActiveWindow
.SplitColumn = 0
.SplitRow = 1
End With

ActiveWindow.FreezePanes = True

xlWS.Range("A1:A1").Select

Set objExcel = Nothing
Set xlWB = Nothing
Set xlWS = Nothing

End Sub

*******************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top