This error just recently began to happen.
I am exporting some records to excel into a preformatted report.
The records are exported successfully but this error pops up before the export is completed.
When I run the debugger this line gives the error message(OBJECT VARIABLE OR WITH BLOCK VARIABLE NOT SET)
If Not (rsSchedules.EOF = True) Then
Below is my code.
1.
querystring is referring to the following query
Expand|Select|Wrap|Line Numbers
- SELECT *
- FROM TblOneDayOnly
- WHERE (ProgIn =3 OR ProgIn =1) AND (ProgOut =3 OR ProgOut =1);
Expand|Select|Wrap|Line Numbers
- Private Sub cmdExport_Click()
- On Error GoTo Finalstep
- Dim querystring As String
- Dim dbase As DAO.Database
- Dim rsSchedules As DAO.Recordset
- Dim tempi As Integer
- Dim rptcnt As Integer
- rptcnt = 0
- If (Me.Optgroup.Value = optScheduleweek.OptionValue Or _
- Me.Optgroup.Value = optcharAdhweek.OptionValue) And _
- (DateTime.Weekday(txtStartDate.Value, 2) <> 5) Then
- MsgBox "The start date is not a Friday, Pls select a friday as start date", vbCritical, "Error"
- Exit Sub
- End If
- querystring = GetQueryString
- If (Len(Trim(querystring)) > 0) Then
- Set dbase = CurrentDb
- If (Me.Optgroup.Value = OptMonthly.OptionValue) Then
- MsgBox "Exporting monthly report for " & CStr(txtStartDate.Value) & _
- " to " & CStr(txtEndDate.Value), vbExclamation, "Export"
- tempi = 1
- Set rsSchedules = dbase.OpenRecordset(querystring)
- If rsSchedules.RecordCount > 0 Then
- rsSchedules.MoveLast
- rptcnt = rsSchedules.RecordCount
- End If
- If rptcnt = 0 Then GoTo Message
- CreateMonthlyReport rsSchedules, GetWeekDay(tempi)
- ElseIf (Me.Optgroup.Value = optScheduleweek.OptionValue) Then
- MsgBox "Exporting One Day Schedule Flight Activity for " & CStr(txtStartDate.Value) & _
- " to " & CStr(txtEndDate.Value), vbExclamation, "Export"
- Set rsSchedules = dbase.OpenRecordset(querystring)
- If Not (rsSchedules.EOF = True) Then
- CreateWeeklyScheduleReport rsSchedules
- rptcnt = 1
- End If
- rsSchedules.Close
- ElseIf (Me.Optgroup.Value = optcharAdhweek.OptionValue) Then
- MsgBox "Exporting One Day Charter & Adhoc report for " & CStr(txtStartDate.Value) & _
- " to " & CStr(txtEndDate.Value), vbExclamation, "Export"
- Set rsSchedules = dbase.OpenRecordset(querystring)
- If Not (rsSchedules.EOF = True) Then
- CreateWeeklyAdhCharReport rsSchedules
- rptcnt = 1
- End If
- rsSchedules.Close
- ElseIf (Me.Optgroup.Value = OptArrivalDate.OptionValue) Then
- MsgBox "Exporting One Day Daily Flight Activity for " & CStr(txtStartDate.Value)
- Set rsSchedules = dbase.OpenRecordset(querystring)
- If Not (rsSchedules.EOF = True) Then
- CreateDailyReport rsSchedules
- rptcnt = 1
- End If
- rsSchedules.Close
- End If
- Message:
- dbase.Close
- If Me.Optgroup.Value <> optcharAdhweek.OptionValue Then
- If (rptcnt = 0) Then
- MsgBox "No Repords Found for Excel Export", vbExclamation, "Export"
- Else
- MsgBox "Export to excel file(s) completed", vbExclamation, "Export Complete"
- End If
- End If
- Set rsSchedules = Nothing
- Set dbase = Nothing
- End If
- Exit Sub
- Finalstep:
- MsgBox Err.Description, vbCritical, "Error"
- End Sub