InitVars Sub or function not defined

accessaspire219

Registered User.
Local time
Today, 05:25
Joined
Jan 16, 2009
Messages
126
I have the following code for the report. When I run the debugger I get an error saying Sub or Function is not defined and InitVars is highlighted.

Code:
Option Compare Database
'Use database order for string comparisons
Option Explicit
'Constant for the maximum number of columns generated by the query
'12 months + 2 years = 14 columns
'Variables for database object and recordset
Dim dbsreport As DAO.Database
Dim rstReport As Recordset
'Variable for number of columns generated by the query
Dim intColumnCount As Integer
Private Sub DetailHeader_Format(Cancel As Integer, FormatCount As Integer)
'Place values into text boxes
Dim IntX As Integer
'Verify that not at the end of the database
If Not rstReport.EOF Then
'If FormatCount is 1, place values from recordset into text boxes in the detail section
If Me.FormatCount = 1 Then
    For IntX = 1 To intColumnCount
    'Convert Null values to 0
    Me("col" + Format(IntX)) = xtabCnulls(rstReport(IntX - 1))
    Next IntX
    
    'Hide unused textboxes in detail section
    For IntX = intColumnCount + 2 To ConTolColumns
    Me("col" + Format(IntX)).Visible = False
    Next IntX
    
    'Move to next record in the recordset
    rstReport.MoveNext
    End If
End If
End Sub
Private Function xtabCnulls(varX As Variant)
'Test if a value is null
If IsNull(varX) Then
    'If a value is null, set VarX=0
    xtabCnulls = 0
Else
    'If it is not null return VarX
    xtabCnulls = varX
End If
End Function
Private Sub DetailHeader_Retreat()
'Always back up to the previous record when detail section retreats
rstReport.MovePrevious
End Sub
Private Sub DescriptionHeader_Format(Cancel As Integer, FormatCount As Integer)
Dim IntX As Integer
'Put column heading into textboxes in the description header
For IntX = 1 To intColumnCount
Me("Head" + Format(IntX)) = rstReport(IntX - 1).NAME
Next IntX
'Hide unused textboxes in the description header
For IntX = (intColumnCount + 2) To conTotalCoumns
Me("Head" + Format(IntX)).Visible = False
Next IntX
End Sub
Private Sub Report_Open(Cancel As Integer)
'Create underlying recordset for report using criteria entered in the Performance_Reports form
Dim IntX As Integer
Dim qdf As DAO.QueryDef
Dim Form As Form
'Do not open report unless the Performance_Reports form is loaded
If Not (IsLoaded("Performance_Reports")) Then
Cancel = True
MsgBox "To preview or print this report, you must open " _
& "Performance_Reports.", vbExclamation, _
"Must Open Form"
Exit Sub
End If
'Set database variable to current database
Set dbsreport = CurrentDb
Set Form = Forms!Performance_Reports
'Open QueryDef object.
'Set qdf=dbs.Report.QueryDefs("All_Buyer_Summary_1")
Set qdf = dbsreport.QueryDefs(Me.RecordSource)
'Open Recordset object
Set rstReport = qdf.OpenRecordset()
'Set a variable to hold the number of columns in crosstab query.
intColumnCount = rstReport.Fields.Count
End Sub
Private Sub Report_Close()
On Error Resume Next
'Close recordset
rstReport.Close
End Sub
Private Sub Report_NoData(Cancel As Integer)
MsgBox "Either you left the month and year blank or no records exist for the criteria you specified.", vbExclamation, "No Records Found"
rstReport.Close
Cancel = True
End Sub
Private Sub PageHeader_Format(Cancel As Integer, FormatCount As Integer)
'Move to first record in he recordset at the begining of the report or when a report is started. (A report is started when you print a report from Print Preview or when you retuen to a previous page while previewing.)
rstReport.MoveFirst
'initialize variables
InitVars
End Sub

How can I define InitVars?
 
Access is looking for a Sub or Function called InitVars containing some commands to perform. I guess you copied this code from somewhere and didn't get the InitVars sub because it was probably located in a standard module.

Incidentally the code is rather clunky.
If the form needs to be open for the report to work then get the code to open it rather than telling the user to do it. It can even be opened hidden if you want.

Test for a user not entering a date before you open the recordset and count the records.
 

Users who are viewing this thread

Back
Top Bottom