View Full Version : Excel file save problem


Dalorax
12-05-2005, 11:39 AM
I have an xls template which i open and store data. I then print and save xls file.
Print works perfect. However, when I go to retrieve the saved xls file I can't see the data. or anything else for that matter.
The code are as follows:

Private Sub btnCustCOA_Click()
On Error GoTo Err_btnCustCOA_Click

Dim strProduct As String
Dim strFor As String
Dim intSize As Integer
Dim objXLApp As Excel.Application
Dim objXLBook As Excel.Workbook
Dim objDataSheet As Excel.Worksheet
Dim objCell As Excel.Range
Dim strBatch As String
Dim strBatch1 As String
Dim rst As ADODB.Recordset
Dim con As Object
Dim strSQL As String


strProduct = Me.cboProductName
strBatch = Me.lstBatch
strBatch1 = strBatch

Set rst = New ADODB.Recordset
Set con = Application.CurrentProject.Connection
strSQL = "SELECT * FROM [qryQualityResults]"
strSQL = strSQL & "WHERE [BatchNum] = '" & strBatch & "'"
rst.Open strSQL, con, 1
rst.MoveFirst


If IsNull(rst![CustBatch]) = False Then
strBatch = rst![CustBatch]
Else
End If



Set objXLBook = GetObject(Application.CurrentProject.Path & "\Template\" & strFor & "COA.xlt")
Set objXLApp = objXLBook.Parent
Set objDataSheet = objXLBook.Worksheets("BD23 " & UCase(strFor))

With objDataSheet
Set objCell = .Range("CustBatch")
objCell.FormulaR1C1 = strBatch
Set objCell = .Range("SOLIDS")
rst.Find "[Test] Like '*SOLIDS*'"
objCell.FormulaR1C1 = rst![QAResult] / 100
Set objCell = .Range("PressFlow")
rst.MoveFirst
rst.Find "[Test] Like '*PRESS FLOW*'"
objCell.FormulaR1C1 = rst![QAResult]
Set objCell = .Range("Sag")
objCell.FormulaR1C1 = "PASS"
Set objCell = .Range("Bake")
objCell.FormulaR1C1 = ("PASS")
Set objCell = .Range("COADate")
objCell.FormulaR1C1 = Date
objXLApp.Visible = True
.PrintOut Copies:=1, Collate:=True
objXLBook.SaveAs Filename:= _
Application.CurrentProject.Path & "\COA\Customer\" & strBatch & " " & Right(strBatch1, 4) & ".xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
objXLBook.Close savechanges:=True
Set objCell = Nothing
Set objXLBook = Nothing
Set objXLApp = Nothing
rst.Close
Set rst = Nothing


End With



Else
End If

Exit_btnCustCOA_Click:
Exit Sub
Err_btnCustCOA_Click:
MsgBox Err.Description
Resume Exit_btnCustCOA_Click

End Sub

What am I doing wrong?