Error "Object variable or With block variable not set"

  • Thread starter Rpt_Me4NotBeingSmart
  • Start date
R

Rpt_Me4NotBeingSmart

I have a form I use for one button clicks for reports. I am getting this
pesky error above when I use the button wizard. The form does not point to
any table since it is used just for generating reports. My code is below. Can
someone help me? I am lost and the stuff I find on the net so far is of no
help to me.

Private Sub Command4_Click()
On Error GoTo Err_Command4_Click

Dim stDocName As String

stDocName = "RptIndvbyName"
DoCmd.OpenReport stDocName, acPreview

Exit_Command4_Click:
Exit Sub

Err_Command4_Click:
MsgBox Err.Description
Resume Exit_Command4_Click

End Sub
Private Sub Command5_Click()
On Error GoTo Err_Command5_Click

Dim stDocName As String

stDocName = "RptIndvbyName"
DoCmd.OpenReport stDocName, acNormal

Exit_Command5_Click:
Exit Sub

Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click

End Sub
Private Sub Command6_Click()
On Error GoTo Err_Command6_Click

Dim stDocName As String

stDocName = "RptIndvbyName"
DoCmd.SendObject acReport, stDocName

Exit_Command6_Click:
Exit Sub

Err_Command6_Click:
MsgBox Err.Description
Resume Exit_Command6_Click

End Sub
Private Sub Command7_Click()
On Error GoTo Err_Command7_Click

Dim stDocName As String

stDocName = "RptIndvbyName"
DoCmd.OutputTo acReport, stDocName

Exit_Command7_Click:
Exit Sub

Err_Command7_Click:
MsgBox Err.Description
Resume Exit_Command7_Click

End Sub
Private Sub Command9_Click()
On Error GoTo Err_Command9_Click

Dim stDocName As String

stDocName = "RptIndvHistByName"
DoCmd.OpenReport stDocName, acPreview

Exit_Command9_Click:
Exit Sub

Err_Command9_Click:
MsgBox Err.Description
Resume Exit_Command9_Click

End Sub
Private Sub Command10_Click()
On Error GoTo Err_Command10_Click

Dim stDocName As String

stDocName = "RptIndvHistByName"
DoCmd.OpenReport stDocName, acNormal

Exit_Command10_Click:
Exit Sub

Err_Command10_Click:
MsgBox Err.Description
Resume Exit_Command10_Click

End Sub
Private Sub Command11_Click()
On Error GoTo Err_Command11_Click

Dim stDocName As String

stDocName = "RptIndvHistByName"
DoCmd.SendObject acReport, stDocName

Exit_Command11_Click:
Exit Sub

Err_Command11_Click:
MsgBox Err.Description
Resume Exit_Command11_Click

End Sub
Private Sub Command12_Click()
On Error GoTo Err_Command12_Click

Dim stDocName As String

stDocName = "RptIndvHistByName"
DoCmd.OutputTo acReport, stDocName

Exit_Command12_Click:
Exit Sub

Err_Command12_Click:
MsgBox Err.Description
Resume Exit_Command12_Click

End Sub
Private Sub Command14_Click()
On Error GoTo Err_Command14_Click

Dim stDocName As String

stDocName = "RptCompleteOccuranceLog"
DoCmd.SendObject acReport, stDocName

Exit_Command14_Click:
Exit Sub

Err_Command14_Click:
MsgBox Err.Description
Resume Exit_Command14_Click

End Sub
Private Sub Command15_Click()
On Error GoTo Err_Command15_Click

Dim stDocName As String

stDocName = "RptCompleteOccuranceLog"
DoCmd.OpenReport stDocName, acPreview

Exit_Command15_Click:
Exit Sub

Err_Command15_Click:
MsgBox Err.Description
Resume Exit_Command15_Click

End Sub
Private Sub Command16_Click()
On Error GoTo Err_Command16_Click

Dim stDocName As String

stDocName = "RptCompleteOccuranceLog"
DoCmd.OpenReport stDocName, acNormal

Exit_Command16_Click:
Exit Sub

Err_Command16_Click:
MsgBox Err.Description
Resume Exit_Command16_Click

End Sub
Private Sub Command17_Click()
On Error GoTo Err_Command17_Click

Dim stDocName As String

stDocName = "RptCompleteOccuranceLog"
DoCmd.OutputTo acReport, stDocName

Exit_Command17_Click:
Exit Sub

Err_Command17_Click:
MsgBox Err.Description
Resume Exit_Command17_Click

End Sub
Private Sub Command19_Click()
On Error GoTo Err_Command19_Click

Dim stDocName As String

stDocName = "RptActiveOccuranceLog"
DoCmd.SendObject acReport, stDocName

Exit_Command19_Click:
Exit Sub

Err_Command19_Click:
MsgBox Err.Description
Resume Exit_Command19_Click

End Sub
Private Sub Command20_Click()
On Error GoTo Err_Command20_Click

Dim stDocName As String

stDocName = "RptActiveOccuranceLog"
DoCmd.OpenReport stDocName, acPreview

Exit_Command20_Click:
Exit Sub

Err_Command20_Click:
MsgBox Err.Description
Resume Exit_Command20_Click

End Sub
Private Sub Command21_Click()
On Error GoTo Err_Command21_Click

Dim stDocName As String

stDocName = "RptActiveOccuranceLog"
DoCmd.OpenReport stDocName, acNormal

Exit_Command21_Click:
Exit Sub

Err_Command21_Click:
MsgBox Err.Description
Resume Exit_Command21_Click

End Sub
Private Sub Command22_Click()
On Error GoTo Err_Command22_Click

Dim stDocName As String

stDocName = "RptActiveOccuranceLog"
DoCmd.OutputTo acReport, stDocName

Exit_Command22_Click:
Exit Sub

Err_Command22_Click:
MsgBox Err.Description
Resume Exit_Command22_Click

End Sub

Private Sub Command24_Click()
On Error GoTo Err_Command24_Click

Dim stDocName As String

stDocName = "RptExpiredOccuranceLog"
DoCmd.SendObject acReport, stDocName

Exit_Command24_Click:
Exit Sub

Err_Command24_Click:
MsgBox Err.Description
Resume Exit_Command24_Click

End Sub
Private Sub Command25_Click()
On Error GoTo Err_Command25_Click

Dim stDocName As String

stDocName = "RptExpiredOccuranceLog"
DoCmd.OpenReport stDocName, acPreview

Exit_Command25_Click:
Exit Sub

Err_Command25_Click:
MsgBox Err.Description
Resume Exit_Command25_Click

End Sub
Private Sub Command26_Click()
On Error GoTo Err_Command26_Click

Dim stDocName As String

stDocName = "RptExpiredOccuranceLog"
DoCmd.OpenReport stDocName, acNormal

Exit_Command26_Click:
Exit Sub

Err_Command26_Click:
MsgBox Err.Description
Resume Exit_Command26_Click

End Sub
Private Sub Command27_Click()
On Error GoTo Err_Command27_Click

Dim stDocName As String

stDocName = "RptExpiredOccuranceLog"
DoCmd.OutputTo acReport, stDocName

Exit_Command27_Click:
Exit Sub

Err_Command27_Click:
MsgBox Err.Description
Resume Exit_Command27_Click

End Sub
Private Sub Command35_Click()
On Error GoTo Err_Command35_Click

Dim stDocName As String

stDocName = "RptIndivHistByAttDate"
DoCmd.OpenReport stDocName, acPreview

Exit_Command35_Click:
Exit Sub

Err_Command35_Click:
MsgBox Err.Description
Resume Exit_Command35_Click

End Sub
Private Sub Command36_Click()
On Error GoTo Err_Command36_Click

Dim stDocName As String

stDocName = "RptIndivHistByAttDate"
DoCmd.OpenReport stDocName, acNormal

Exit_Command36_Click:
Exit Sub

Err_Command36_Click:
MsgBox Err.Description
Resume Exit_Command36_Click

End Sub
Private Sub Command37_Click()
On Error GoTo Err_Command37_Click

Dim stDocName As String

stDocName = "RptIndivHistByAttDate"
DoCmd.SendObject acReport, stDocName

Exit_Command37_Click:
Exit Sub

Err_Command37_Click:
MsgBox Err.Description
Resume Exit_Command37_Click

End Sub
Private Sub Command38_Click()
On Error GoTo Err_Command38_Click

Dim stDocName As String

stDocName = "RptIndivHistByAttDate"
DoCmd.OutputTo acReport, stDocName

Exit_Command38_Click:
Exit Sub

Err_Command38_Click:
MsgBox Err.Description
Resume Exit_Command38_Click

End Sub
Private Sub Command42_Click()
On Error GoTo Err_Command42_Click

Dim stDocName As String

stDocName = "RptActiveOccuranceLogByDept"
DoCmd.OpenReport stDocName, acPreview

Exit_Command42_Click:
Exit Sub

Err_Command42_Click:
MsgBox Err.Description
Resume Exit_Command42_Click

End Sub
Private Sub Command43_Click()
On Error GoTo Err_Command43_Click

Dim stDocName As String

stDocName = "RptActiveOccuranceLogByDept"
DoCmd.OpenReport stDocName, acNormal

Exit_Command43_Click:
Exit Sub

Err_Command43_Click:
MsgBox Err.Description
Resume Exit_Command43_Click

End Sub
Private Sub Command44_Click()
On Error GoTo Err_Command44_Click

Dim stDocName As String

stDocName = "RptActiveOccuranceLogByDept"
DoCmd.SendObject acReport, stDocName

Exit_Command44_Click:
Exit Sub

Err_Command44_Click:
MsgBox Err.Description
Resume Exit_Command44_Click

End Sub
Private Sub Command45_Click()
On Error GoTo Err_Command45_Click

Dim stDocName As String

stDocName = "RptActiveOccuranceLogByDept"
DoCmd.OutputTo acReport, stDocName

Exit_Command45_Click:
Exit Sub

Err_Command45_Click:
MsgBox Err.Description
Resume Exit_Command45_Click

End Sub
Private Sub Command52_Click()
On Error GoTo Err_Command52_Click

Dim stDocName As String

stDocName = "RptActiveOccuranceLogbyDeptandDate"
DoCmd.OpenReport stDocName, acPreview

Exit_Command52_Click:
Exit Sub

Err_Command52_Click:
MsgBox Err.Description
Resume Exit_Command52_Click

End Sub
Private Sub Command53_Click()
On Error GoTo Err_Command53_Click

Dim stDocName As String

stDocName = "RptActiveOccuranceLogbyDeptandDate"
DoCmd.OpenReport stDocName, acNormal

Exit_Command53_Click:
Exit Sub

Err_Command53_Click:
MsgBox Err.Description
Resume Exit_Command53_Click

End Sub
Private Sub Command54_Click()
On Error GoTo Err_Command54_Click

Dim stDocName As String

stDocName = "RptActiveOccuranceLogbyDeptandDate"
DoCmd.SendObject acReport, stDocName

Exit_Command54_Click:
Exit Sub

Err_Command54_Click:
MsgBox Err.Description
Resume Exit_Command54_Click

End Sub
Private Sub Command55_Click()
On Error GoTo Err_Command55_Click

Dim stDocName As String

stDocName = "RptActiveOccuranceLogbyDeptandDate"
DoCmd.OutputTo acReport, stDocName

Exit_Command55_Click:
Exit Sub

Err_Command55_Click:
MsgBox Err.Description
Resume Exit_Command55_Click

End Sub
Private Sub Command64_Click()
On Error GoTo Err_Command64_Click


DoCmd.Close

Exit_Command64_Click:
Exit Sub

Err_Command64_Click:
MsgBox Err.Description
Resume Exit_Command64_Click

End Sub
Private Sub Command67_Click()
On Error GoTo Err_Command67_Click

Dim stDocName As String

stDocName = "RptIndivActiveUnaddressed"
DoCmd.OpenReport stDocName, acPreview

Exit_Command67_Click:
Exit Sub

Err_Command67_Click:
MsgBox Err.Description
Resume Exit_Command67_Click

End Sub
Private Sub Command68_Click()
On Error GoTo Err_Command68_Click

Dim stDocName As String

stDocName = "RptIndivActiveUnaddressed"
DoCmd.OpenReport stDocName, acNormal

Exit_Command68_Click:
Exit Sub

Err_Command68_Click:
MsgBox Err.Description
Resume Exit_Command68_Click

End Sub
Private Sub Command69_Click()
On Error GoTo Err_Command69_Click

Dim stDocName As String

stDocName = "RptIndivActiveUnaddressed"
DoCmd.SendObject acReport, stDocName

Exit_Command69_Click:
Exit Sub

Err_Command69_Click:
MsgBox Err.Description
Resume Exit_Command69_Click

End Sub
Private Sub Command70_Click()
On Error GoTo Err_Command70_Click

Dim stDocName As String

stDocName = "RptIndivActiveUnaddressed"
DoCmd.OutputTo acReport, stDocName

Exit_Command70_Click:
Exit Sub

Err_Command70_Click:
MsgBox Err.Description
Resume Exit_Command70_Click

End Sub
Private Sub Command73_Click()
On Error GoTo Err_Command73_Click

Dim stDocName As String

stDocName = "RptActvieOccuranceLogbyDeptUnaddressed"
DoCmd.OpenReport stDocName, acPreview

Exit_Command73_Click:
Exit Sub

Err_Command73_Click:
MsgBox Err.Description
Resume Exit_Command73_Click

End Sub
Private Sub Command74_Click()
On Error GoTo Err_Command74_Click

Dim stDocName As String

stDocName = "RptActvieOccuranceLogbyDeptUnaddressed"
DoCmd.OpenReport stDocName, acNormal

Exit_Command74_Click:
Exit Sub

Err_Command74_Click:
MsgBox Err.Description
Resume Exit_Command74_Click

End Sub
Private Sub Command75_Click()
On Error GoTo Err_Command75_Click

Dim stDocName As String

stDocName = "RptActvieOccuranceLogbyDeptUnaddressed"
DoCmd.SendObject acReport, stDocName

Exit_Command75_Click:
Exit Sub

Err_Command75_Click:
MsgBox Err.Description
Resume Exit_Command75_Click

End Sub
Private Sub Command76_Click()
On Error GoTo Err_Command76_Click

Dim stDocName As String

stDocName = "RptActvieOccuranceLogbyDeptUnaddressed"
DoCmd.OutputTo acReport, stDocName

Exit_Command76_Click:
Exit Sub

Err_Command76_Click:
MsgBox Err.Description
Resume Exit_Command76_Click

End Sub
Private Sub Command77_Click()
On Error GoTo Err_Command77_Click

Dim stDocName As String

stDocName = "RptDisciplinebyName"
DoCmd.OpenReport stDocName, acPreview

Exit_Command77_Click:
Exit Sub

Err_Command77_Click:
MsgBox Err.Description
Resume Exit_Command77_Click

End Sub
Private Sub Command80_Click()
On Error GoTo Err_Command80_Click

Dim stDocName As String

stDocName = "RptOutListOnDateRangeWithExplanations"
DoCmd.OpenReport stDocName, acPreview

Exit_Command80_Click:
Exit Sub

Err_Command80_Click:
MsgBox Err.Description
Resume Exit_Command80_Click

End Sub
Private Sub Command85_Click()
On Error GoTo Err_Command85_Click

Dim stDocName As String

stDocName = "RptOutListOnDateRangeWithExplanations"
DoCmd.OutputTo acReport, stDocName

Exit_Command85_Click:
Exit Sub

Err_Command85_Click:
MsgBox Err.Description
Resume Exit_Command85_Click

End Sub
Private Sub Command86_Click()
On Error GoTo Err_Command86_Click

Dim stDocName As String

stDocName = "RptOutListOnDateRangeWithExplanations"
DoCmd.OpenReport stDocName, acNormal

Exit_Command86_Click:
Exit Sub

Err_Command86_Click:
MsgBox Err.Description
Resume Exit_Command86_Click

End Sub
Private Sub Command87_Click()
On Error GoTo Err_Command87_Click

Dim stDocName As String

stDocName = "RptOutListOnDateRangeWithExplanations"
DoCmd.OutputTo acReport, stDocName

Exit_Command87_Click:
Exit Sub

Err_Command87_Click:
MsgBox Err.Description
Resume Exit_Command87_Click

End Sub
 
B

BruceM

Does this happen when you click a particular button? If so, which one? If
not, how exactly is the error generated?
 
B

Beetle284 via AccessMonster.com

Uummmm................Wow!

You're using (rough count) 47 command buttons to handle this? What
happens when you add another report? Four of Five more command
buttons, along with code for each?

Can I make a suggestion?

This could easily be handled with a couple of combo boxes and one
command button. Then you wouldn't have to redesign your form when
you add a new report, and you might have some hope of making sense
out of your code.

First, store your report names in a small table. If you don't want your
users to see the actual report names (like "RptIndvbyName") then add
a field for a user friendly description, so the table structure might look
like;

tblReports
********
ReportName (Text - Primary key)
ReportDescription (Text)

and the data would look like;

ReportName ReportDescription
RptIndvbyName Individual By Name
RptIndvHistByName Individual History By name

Next, put a combo box on your form that uses this table as a row source.
The properties of this combo would look like;

Name - cboSelectReport
Row Source Type - Table/Query
Row Source - "Select ReportName, ReportDescription From tblReports
Order By ReportDescription"
Bound Column - 1
Column Count - 2
Column Widths - 0", 2"

Then add another combo box for selecting what to do with the report
with properties like;

Name - cboReportOutput
Row Source Type - Value List
Row Source - Print Report; Preview Report; E-mail Report; Save To File
Bound Column - 1
Column Count - 1
Column Widths - 2

Then you could have *one* command button (i.e. cmdExecute) with
code like;

Private Sub cmdExecute_Click ()

Dim stDocName As String

stDocName = Me!cboSelectReport

Select Case Me!cboReportOutput
Case "Print Report"
Docmd.OpenReport stDocName, acNormal
Case "Preview Report"
DoCmd.OpenReport stDocName, acViewPreview
Case "E-Mail Report"
DoCmd.SendObject acReport, stDocName
Case "Save To File"
DoCmd.OutputTo acReport, stDocName
End Select

End Sub

That way, when you inevitably create more reports in the future, all you
have to do is add the report name to your table.
 
R

Rpt_Me4NotBeingSmart

I actually did this from the time I posted this and now. It works beautifuly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top