winxmun
12-30-2010, 07:02 PM
Hi,
I hv a VBA code that is running a query & thereafter export to an Excel File. However there will be an error message pop up if is a NIL record. May I know how to prompt a message with "No Record" instead of an error message? Tks a lot!:dunno
DoCmd.SetWarnings False
DoCmd.OpenQuery "Qry_Expected_No_of_Redemp_CO"
DoCmd.SetWarnings True
'---------------------Export AccessQuery_Qry_Expected_No_of_Redemp_CO---------------
Set dbs = CurrentDb
Set Rst = dbs.OpenRecordset("Expected_No_of_Redemp_CO", dbOpenSnapshot)
Rst.MoveLast
intRow = Rst.RecordCount
Rst.MoveFirst
initRowExcel = 2
x = 1
y = initRowExcel
avarRecords = Rst.GetRows(intRow)
intRow = UBound(avarRecords, 2) + 1
intCol = UBound(avarRecords, 1) + 1
'-------------------open excel----------------------------------------
Set appXL = CreateObject("excel.application")
appXL.Visible = True
Set wbk = GetObject("d:\HDB_Expected_No_of_Redemp_CO.xls")
Set wbs1 = wbk.Worksheets(1)
wbk.Parent.Windows(1).Visible = True
For intRow = 0 To intRow - 1
For intCol = 0 To intCol - 1
wbs1.Cells(y, x).Value = avarRecords(intCol, intRow)
x = x + 1
Next intCol
x = 1
y = y + 1
Next intRow
Rst.Close
Happy New Year!
I hv a VBA code that is running a query & thereafter export to an Excel File. However there will be an error message pop up if is a NIL record. May I know how to prompt a message with "No Record" instead of an error message? Tks a lot!:dunno
DoCmd.SetWarnings False
DoCmd.OpenQuery "Qry_Expected_No_of_Redemp_CO"
DoCmd.SetWarnings True
'---------------------Export AccessQuery_Qry_Expected_No_of_Redemp_CO---------------
Set dbs = CurrentDb
Set Rst = dbs.OpenRecordset("Expected_No_of_Redemp_CO", dbOpenSnapshot)
Rst.MoveLast
intRow = Rst.RecordCount
Rst.MoveFirst
initRowExcel = 2
x = 1
y = initRowExcel
avarRecords = Rst.GetRows(intRow)
intRow = UBound(avarRecords, 2) + 1
intCol = UBound(avarRecords, 1) + 1
'-------------------open excel----------------------------------------
Set appXL = CreateObject("excel.application")
appXL.Visible = True
Set wbk = GetObject("d:\HDB_Expected_No_of_Redemp_CO.xls")
Set wbs1 = wbk.Worksheets(1)
wbk.Parent.Windows(1).Visible = True
For intRow = 0 To intRow - 1
For intCol = 0 To intCol - 1
wbs1.Cells(y, x).Value = avarRecords(intCol, intRow)
x = x + 1
Next intCol
x = 1
y = y + 1
Next intRow
Rst.Close
Happy New Year!