I keep getting an error stating OBJECT VARIABLE OR WITH BLOCK VARIABLE NOT SET.
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.EO F = True) Then
Below is my code.
1.
querystring is referring to the following query
[code=sql]SELECT *
FROM TblOneDayOnly
WHERE (ProgIn =3 OR ProgIn =1) AND (ProgOut =3 OR ProgOut =1);[/code]
[code=vb]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.Va lue = optScheduleweek .OptionValue Or _
Me.Optgroup.Val ue = optcharAdhweek. OptionValue) And _
(DateTime.Weekd ay(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(query string)) > 0) Then
Set dbase = CurrentDb
If (Me.Optgroup.Va lue = OptMonthly.Opti onValue) Then
MsgBox "Exporting monthly report for " & CStr(txtStartDa te.Value) & _
" to " & CStr(txtEndDate .Value), vbExclamation, "Export"
tempi = 1
Set rsSchedules = dbase.OpenRecor dset(querystrin g)
If rsSchedules.Rec ordCount > 0 Then
rsSchedules.Mov eLast
rptcnt = rsSchedules.Rec ordCount
End If
If rptcnt = 0 Then GoTo Message
CreateMonthlyRe port rsSchedules, GetWeekDay(temp i)
ElseIf (Me.Optgroup.Va lue = optScheduleweek .OptionValue) Then
MsgBox "Exporting One Day Schedule Flight Activity for " & CStr(txtStartDa te.Value) & _
" to " & CStr(txtEndDate .Value), vbExclamation, "Export"
Set rsSchedules = dbase.OpenRecor dset(querystrin g)
If Not (rsSchedules.EO F = True) Then
CreateWeeklySch eduleReport rsSchedules
rptcnt = 1
End If
rsSchedules.Clo se
ElseIf (Me.Optgroup.Va lue = optcharAdhweek. OptionValue) Then
MsgBox "Exporting One Day Charter & Adhoc report for " & CStr(txtStartDa te.Value) & _
" to " & CStr(txtEndDate .Value), vbExclamation, "Export"
Set rsSchedules = dbase.OpenRecor dset(querystrin g)
If Not (rsSchedules.EO F = True) Then
CreateWeeklyAdh CharReport rsSchedules
rptcnt = 1
End If
rsSchedules.Clo se
ElseIf (Me.Optgroup.Va lue = OptArrivalDate. OptionValue) Then
MsgBox "Exporting One Day Daily Flight Activity for " & CStr(txtStartDa te.Value)
Set rsSchedules = dbase.OpenRecor dset(querystrin g)
If Not (rsSchedules.EO F = True) Then
CreateDailyRepo rt rsSchedules
rptcnt = 1
End If
rsSchedules.Clo se
End If
Message:
dbase.Close
If Me.Optgroup.Val ue <> 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[/code]
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.EO F = True) Then
Below is my code.
1.
querystring is referring to the following query
[code=sql]SELECT *
FROM TblOneDayOnly
WHERE (ProgIn =3 OR ProgIn =1) AND (ProgOut =3 OR ProgOut =1);[/code]
[code=vb]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.Va lue = optScheduleweek .OptionValue Or _
Me.Optgroup.Val ue = optcharAdhweek. OptionValue) And _
(DateTime.Weekd ay(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(query string)) > 0) Then
Set dbase = CurrentDb
If (Me.Optgroup.Va lue = OptMonthly.Opti onValue) Then
MsgBox "Exporting monthly report for " & CStr(txtStartDa te.Value) & _
" to " & CStr(txtEndDate .Value), vbExclamation, "Export"
tempi = 1
Set rsSchedules = dbase.OpenRecor dset(querystrin g)
If rsSchedules.Rec ordCount > 0 Then
rsSchedules.Mov eLast
rptcnt = rsSchedules.Rec ordCount
End If
If rptcnt = 0 Then GoTo Message
CreateMonthlyRe port rsSchedules, GetWeekDay(temp i)
ElseIf (Me.Optgroup.Va lue = optScheduleweek .OptionValue) Then
MsgBox "Exporting One Day Schedule Flight Activity for " & CStr(txtStartDa te.Value) & _
" to " & CStr(txtEndDate .Value), vbExclamation, "Export"
Set rsSchedules = dbase.OpenRecor dset(querystrin g)
If Not (rsSchedules.EO F = True) Then
CreateWeeklySch eduleReport rsSchedules
rptcnt = 1
End If
rsSchedules.Clo se
ElseIf (Me.Optgroup.Va lue = optcharAdhweek. OptionValue) Then
MsgBox "Exporting One Day Charter & Adhoc report for " & CStr(txtStartDa te.Value) & _
" to " & CStr(txtEndDate .Value), vbExclamation, "Export"
Set rsSchedules = dbase.OpenRecor dset(querystrin g)
If Not (rsSchedules.EO F = True) Then
CreateWeeklyAdh CharReport rsSchedules
rptcnt = 1
End If
rsSchedules.Clo se
ElseIf (Me.Optgroup.Va lue = OptArrivalDate. OptionValue) Then
MsgBox "Exporting One Day Daily Flight Activity for " & CStr(txtStartDa te.Value)
Set rsSchedules = dbase.OpenRecor dset(querystrin g)
If Not (rsSchedules.EO F = True) Then
CreateDailyRepo rt rsSchedules
rptcnt = 1
End If
rsSchedules.Clo se
End If
Message:
dbase.Close
If Me.Optgroup.Val ue <> 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[/code]
Comment