Skip Bisconer
Who Me?
- Local time
- Today, 15:48
- Joined
- Jan 22, 2008
- Messages
- 285
I have a function with 13 sets of the following code to clear Excel files to prepare for the next period. My problem comes when the linked file has no records. This process destroys the column headers of an empty file. Could some one advise me on getting past the do loop when there is no records in the spreadsheet.
Code:
DoCmd.SetWarnings False
DoCmd.OpenQuery "PostToCompletedMonthlyTransaction12085", acViewNormal
DoCmd.OpenQuery "PostToHistoryCurrentCharges12085", acViewNormal
DoCmd.SetWarnings True
Set xlWB = objXL.Workbooks.Open("C:\Amex\CurrentChargesBriare.xls")
Set xlWS = xlWB.Worksheets("CurrentCharges")
xlWB.Worksheets("CurrentCharges").Unprotect Password:=("1234")
Set db = CurrentDb
Set rs = db.OpenRecordset("CurrentCharges12085", , dbOpenDynamic)
If rs.BOF And rs.EOF Then
MsgBox "There are no records for Briare" [COLOR=red]'My problem is here I need what comes after the msgbos to get past Else.[/COLOR]
Else
rs.MoveFirst
i = 2
Do Until rs.EOF
With xlWS
' assign records to specific cells
.Range("A" & i).Value = ""
.Range("B" & i).Value = ""
.Range("C" & i).Value = ""
.Range("D" & i).Value = ""
.Range("E" & i).Value = ""
.Range("F" & i).Value = ""
.Range("G" & i).Value = ""
.Range("H" & i).Value = ""
.Range("I" & i).Value = ""
.Range("J" & i).Value = ""
.Range("K" & i).Value = ""
.Range("L" & i).Value = ""
.Range("M" & i).Value = ""
.Range("N" & i).Value = ""
End With
i = i + 1
rs.MoveNext
Loop
End If
xlWB.Worksheets("CurrentCharges").Protect Password:=("1234")
objXL.ActiveWorkbook.Save
objXL.Application.Quit
rs.Close
db.Close