OnPrint Function Error

P

Pam

Please forgive the repost of the same topic, but I really need to get a
table of content report and keep getting error msg "Type Mismatch" for the
OnPrint function. I have followed the instruction from the Ms Article for
creating a table of contents in both the Northwind db and my db. It works
perfectly in Northwind, but my report gives the error. My grouping header
is PartNumber - it is a text field containg both numbers and text. I've
checked the "description" field in the toc table and it is text set to the
same number of characters as partnumber. I've searched thru post and web
looking for answer to what I'm doing wrong.

If anyone has answer, please let me know how to solve this VERY frustrating
problem.

Thanks,
Pam
 
M

Marshall Barton

Pam said:
Please forgive the repost of the same topic, but I really need to get a
table of content report and keep getting error msg "Type Mismatch" for the
OnPrint function. I have followed the instruction from the Ms Article for
creating a table of contents in both the Northwind db and my db. It works
perfectly in Northwind, but my report gives the error. My grouping header
is PartNumber - it is a text field containg both numbers and text. I've
checked the "description" field in the toc table and it is text set to the
same number of characters as partnumber. I've searched thru post and web
looking for answer to what I'm doing wrong.


It's hard to tell without seeing the code you are using.

Note that I have never heard of an OnPrint function. There
is an OnPrint **property** associated with report sections.
Normally, the OnPrint property contains:
[Event Procedure]
which means the Print event **procedure** is declared as:
Sub <section name>_Print( . . . )

OTOH, it is possible to call a function directly from the
OnPrint property by using the syntax:
=somefunctionanme(argumentlist)
If this is what you have, that error message could mean that
you have a text string in an argument that the function
declared as a number type. Or, maybe the function itself is
using a variable inappropriately??
 
P

Pam

Marshall,

Thank you for the quick response. Sorry about using "function" in the
OnPrint error description. I've included the code I'm using. Hopefully,
you will be able to tell why this won't work for me.

Thanks again,
Pam


Option Compare Database

Dim db As DAO.Database
Dim TocTable As DAO.Recordset


Function InitToc()
Set db = CurrentDb()
db.Execute "Delete* From [Table Of Contents]"
Set TocTable = db.OpenRecordset("Table Of Contents", dbOpenTable)
TocTable.Index = "Description"

End Function

Function UpdateToc(TocEntry As String, Rpt As Report)
TocTable.Seek "=", TocEntry

If TocTable.NoMatch Then
TocTable.AddNew
TocTable!Description = TocEntry
TocTable![Page Number] = Rpt.Page
TocTable.Update
End If

End Function
OnOpen Property for report
=InitToc()

OnPrint Property for group (partnumber) header
=UpdateToc([PartNumber],[Report])

Marshall Barton said:
Pam said:
Please forgive the repost of the same topic, but I really need to get a
table of content report and keep getting error msg "Type Mismatch" for the
OnPrint function. I have followed the instruction from the Ms Article for
creating a table of contents in both the Northwind db and my db. It works
perfectly in Northwind, but my report gives the error. My grouping header
is PartNumber - it is a text field containg both numbers and text. I've
checked the "description" field in the toc table and it is text set to the
same number of characters as partnumber. I've searched thru post and web
looking for answer to what I'm doing wrong.


It's hard to tell without seeing the code you are using.

Note that I have never heard of an OnPrint function. There
is an OnPrint **property** associated with report sections.
Normally, the OnPrint property contains:
[Event Procedure]
which means the Print event **procedure** is declared as:
Sub <section name>_Print( . . . )

OTOH, it is possible to call a function directly from the
OnPrint property by using the syntax:
=somefunctionanme(argumentlist)
If this is what you have, that error message could mean that
you have a text string in an argument that the function
declared as a number type. Or, maybe the function itself is
using a variable inappropriately??
 
M

Marshall Barton

That looks good to me. Is there any chance that there might
be a record where the PartNumber field is Null? If so, try
using:

=UpdateToc(Nz([PartNumber], "Unknown Part", [Report])
--
Marsh
MVP [MS Access]

Thank you for the quick response. Sorry about using "function" in the
OnPrint error description. I've included the code I'm using. Hopefully,
you will be able to tell why this won't work for me.


Option Compare Database

Dim db As DAO.Database
Dim TocTable As DAO.Recordset


Function InitToc()
Set db = CurrentDb()
db.Execute "Delete* From [Table Of Contents]"
Set TocTable = db.OpenRecordset("Table Of Contents", dbOpenTable)
TocTable.Index = "Description"

End Function

Function UpdateToc(TocEntry As String, Rpt As Report)
TocTable.Seek "=", TocEntry

If TocTable.NoMatch Then
TocTable.AddNew
TocTable!Description = TocEntry
TocTable![Page Number] = Rpt.Page
TocTable.Update
End If

End Function
OnOpen Property for report
=InitToc()

OnPrint Property for group (partnumber) header
=UpdateToc([PartNumber],[Report])

 
P

Pam

Marsh,

There is a PartNumber for every record in the query backing this report. I
tried the code you provided but received error "The expression entered has a
function containing the wrong number of arguments."

Do you have any other suggestions? I just can't get anything to work with
this but using the same code and only changing the name of the header group,
it works in the Northwind sample db.

Thanks again for your help,
Pam

Marshall Barton said:
That looks good to me. Is there any chance that there might
be a record where the PartNumber field is Null? If so, try
using:

=UpdateToc(Nz([PartNumber], "Unknown Part", [Report])
--
Marsh
MVP [MS Access]

Thank you for the quick response. Sorry about using "function" in the
OnPrint error description. I've included the code I'm using. Hopefully,
you will be able to tell why this won't work for me.


Option Compare Database

Dim db As DAO.Database
Dim TocTable As DAO.Recordset


Function InitToc()
Set db = CurrentDb()
db.Execute "Delete* From [Table Of Contents]"
Set TocTable = db.OpenRecordset("Table Of Contents", dbOpenTable)
TocTable.Index = "Description"

End Function

Function UpdateToc(TocEntry As String, Rpt As Report)
TocTable.Seek "=", TocEntry

If TocTable.NoMatch Then
TocTable.AddNew
TocTable!Description = TocEntry
TocTable![Page Number] = Rpt.Page
TocTable.Update
End If

End Function
OnOpen Property for report
=InitToc()

OnPrint Property for group (partnumber) header
=UpdateToc([PartNumber],[Report])

Pam wrote:
Please forgive the repost of the same topic, but I really need to get a
table of content report and keep getting error msg "Type Mismatch" for
the
OnPrint function. I have followed the instruction from the Ms Article
for
creating a table of contents in both the Northwind db and my db. It
works
perfectly in Northwind, but my report gives the error. My grouping
header
is PartNumber - it is a text field containg both numbers and text. I've
checked the "description" field in the toc table and it is text set to
the
same number of characters as partnumber. I've searched thru post and
web
looking for answer to what I'm doing wrong.
 
M

Marshall Barton

I was missing a )

=UpdateToc(Nz([PartNumber], "Unknown Part"), [Report])

But, from what you've posted, if it's not a Null part
number, I don't see where you would get a type mismatch
error. Are you sure it's not coming from some other code?
Have you stepped through the code or used nreak points to
isolate the line with the error.
--
Marsh
MVP [MS Access]

There is a PartNumber for every record in the query backing this report. I
tried the code you provided but received error "The expression entered has a
function containing the wrong number of arguments."

Do you have any other suggestions? I just can't get anything to work with
this but using the same code and only changing the name of the header group,
it works in the Northwind sample db.
Thank you for the quick response. Sorry about using "function" in the
OnPrint error description. I've included the code I'm using. Hopefully,
you will be able to tell why this won't work for me.


Option Compare Database

Dim db As DAO.Database
Dim TocTable As DAO.Recordset


Function InitToc()
Set db = CurrentDb()
db.Execute "Delete* From [Table Of Contents]"
Set TocTable = db.OpenRecordset("Table Of Contents", dbOpenTable)
TocTable.Index = "Description"

End Function

Function UpdateToc(TocEntry As String, Rpt As Report)
TocTable.Seek "=", TocEntry

If TocTable.NoMatch Then
TocTable.AddNew
TocTable!Description = TocEntry
TocTable![Page Number] = Rpt.Page
TocTable.Update
End If

End Function
OnOpen Property for report
=InitToc()

OnPrint Property for group (partnumber) header
=UpdateToc([PartNumber],[Report])


Pam wrote:
Please forgive the repost of the same topic, but I really need to get a
table of content report and keep getting error msg "Type Mismatch" for
the
OnPrint function. I have followed the instruction from the Ms Article
for
creating a table of contents in both the Northwind db and my db. It
works
perfectly in Northwind, but my report gives the error. My grouping
header
is PartNumber - it is a text field containg both numbers and text. I've
checked the "description" field in the toc table and it is text set to
the
same number of characters as partnumber. I've searched thru post and
web
looking for answer to what I'm doing wrong.
 
P

Pam

Marsh,

I tried revised code, but you guessed - it still didn't work: Type
Mismatch. I went to the module and placed the cursor at the beginning line
of InitToc and selected Debug>Step Into and it highlighted the line yellow.
I went thru the remaining lines in this function and then Step Out. When I
tried to do the same for UpdateToc, it wouldn't highlight only a (blocked?)
type sound from computer. I'm sorry - I know this sounds strange to you,
but I've not worked with "stepping thru code" enough to know exactly what I
should be doing. I still don't understand if it is with the UpdateToc
coding why it works on the sample db.
Does this give you any clues as to what is wrong?
Pam
Marshall Barton said:
I was missing a )

=UpdateToc(Nz([PartNumber], "Unknown Part"), [Report])

But, from what you've posted, if it's not a Null part
number, I don't see where you would get a type mismatch
error. Are you sure it's not coming from some other code?
Have you stepped through the code or used nreak points to
isolate the line with the error.
--
Marsh
MVP [MS Access]

There is a PartNumber for every record in the query backing this report.
I
tried the code you provided but received error "The expression entered has
a
function containing the wrong number of arguments."

Do you have any other suggestions? I just can't get anything to work with
this but using the same code and only changing the name of the header
group,
it works in the Northwind sample db.
Pam wrote:
Thank you for the quick response. Sorry about using "function" in the
OnPrint error description. I've included the code I'm using.
Hopefully,
you will be able to tell why this won't work for me.


Option Compare Database

Dim db As DAO.Database
Dim TocTable As DAO.Recordset


Function InitToc()
Set db = CurrentDb()
db.Execute "Delete* From [Table Of Contents]"
Set TocTable = db.OpenRecordset("Table Of Contents", dbOpenTable)
TocTable.Index = "Description"

End Function

Function UpdateToc(TocEntry As String, Rpt As Report)
TocTable.Seek "=", TocEntry

If TocTable.NoMatch Then
TocTable.AddNew
TocTable!Description = TocEntry
TocTable![Page Number] = Rpt.Page
TocTable.Update
End If

End Function
OnOpen Property for report
=InitToc()

OnPrint Property for group (partnumber) header
=UpdateToc([PartNumber],[Report])


Pam wrote:
Please forgive the repost of the same topic, but I really need to get
a
table of content report and keep getting error msg "Type Mismatch" for
the
OnPrint function. I have followed the instruction from the Ms Article
for
creating a table of contents in both the Northwind db and my db. It
works
perfectly in Northwind, but my report gives the error. My grouping
header
is PartNumber - it is a text field containg both numbers and text.
I've
checked the "description" field in the toc table and it is text set to
the
same number of characters as partnumber. I've searched thru post and
web
looking for answer to what I'm doing wrong.
 
M

Marshall Barton

Try placing a break point on the first line in the UpdateToc
function (just clisk on the left margin of the line and it
will turn dark red when it's set). Then switch the report
to Preview and the code will stop when it hits the break
point. See what you can learn from stepping through from
there.
--
Marsh
MVP [MS Access]

I tried revised code, but you guessed - it still didn't work: Type
Mismatch. I went to the module and placed the cursor at the beginning line
of InitToc and selected Debug>Step Into and it highlighted the line yellow.
I went thru the remaining lines in this function and then Step Out. When I
tried to do the same for UpdateToc, it wouldn't highlight only a (blocked?)
type sound from computer. I'm sorry - I know this sounds strange to you,
but I've not worked with "stepping thru code" enough to know exactly what I
should be doing. I still don't understand if it is with the UpdateToc
coding why it works on the sample db.
Does this give you any clues as to what is wrong?

"Marshall Barton" wrote
I was missing a )

=UpdateToc(Nz([PartNumber], "Unknown Part"), [Report])

But, from what you've posted, if it's not a Null part
number, I don't see where you would get a type mismatch
error. Are you sure it's not coming from some other code?
Have you stepped through the code or used nreak points to
isolate the line with the error.

There is a PartNumber for every record in the query backing this report.
I tried the code you provided but received error "The expression entered has
a function containing the wrong number of arguments."


Pam wrote:
Thank you for the quick response. Sorry about using "function" in the
OnPrint error description. I've included the code I'm using.
Hopefully,
you will be able to tell why this won't work for me.

Option Compare Database

Dim db As DAO.Database
Dim TocTable As DAO.Recordset


Function InitToc()
Set db = CurrentDb()
db.Execute "Delete* From [Table Of Contents]"
Set TocTable = db.OpenRecordset("Table Of Contents", dbOpenTable)
TocTable.Index = "Description"

End Function

Function UpdateToc(TocEntry As String, Rpt As Report)
TocTable.Seek "=", TocEntry

If TocTable.NoMatch Then
TocTable.AddNew
TocTable!Description = TocEntry
TocTable![Page Number] = Rpt.Page
TocTable.Update
End If

End Function
OnOpen Property for report
=InitToc()

OnPrint Property for group (partnumber) header
=UpdateToc([PartNumber],[Report])
 
P

Pam

I did as you suggested and am now getting error msg: Access can't find the
macro: '=UpdateToc(Nz([PartNumber], "Unknown Part"), [Report])'


Marshall Barton said:
Try placing a break point on the first line in the UpdateToc
function (just clisk on the left margin of the line and it
will turn dark red when it's set). Then switch the report
to Preview and the code will stop when it hits the break
point. See what you can learn from stepping through from
there.
--
Marsh
MVP [MS Access]

I tried revised code, but you guessed - it still didn't work: Type
Mismatch. I went to the module and placed the cursor at the beginning
line
of InitToc and selected Debug>Step Into and it highlighted the line
yellow.
I went thru the remaining lines in this function and then Step Out. When
I
tried to do the same for UpdateToc, it wouldn't highlight only a
(blocked?)
type sound from computer. I'm sorry - I know this sounds strange to you,
but I've not worked with "stepping thru code" enough to know exactly what
I
should be doing. I still don't understand if it is with the UpdateToc
coding why it works on the sample db.
Does this give you any clues as to what is wrong?

"Marshall Barton" wrote
I was missing a )

=UpdateToc(Nz([PartNumber], "Unknown Part"), [Report])

But, from what you've posted, if it's not a Null part
number, I don't see where you would get a type mismatch
error. Are you sure it's not coming from some other code?
Have you stepped through the code or used nreak points to
isolate the line with the error.


Pam wrote:
There is a PartNumber for every record in the query backing this report.
I tried the code you provided but received error "The expression entered
has
a function containing the wrong number of arguments."


Pam wrote:
Thank you for the quick response. Sorry about using "function" in the
OnPrint error description. I've included the code I'm using.
Hopefully,
you will be able to tell why this won't work for me.

Option Compare Database

Dim db As DAO.Database
Dim TocTable As DAO.Recordset


Function InitToc()
Set db = CurrentDb()
db.Execute "Delete* From [Table Of Contents]"
Set TocTable = db.OpenRecordset("Table Of Contents", dbOpenTable)
TocTable.Index = "Description"

End Function

Function UpdateToc(TocEntry As String, Rpt As Report)
TocTable.Seek "=", TocEntry

If TocTable.NoMatch Then
TocTable.AddNew
TocTable!Description = TocEntry
TocTable![Page Number] = Rpt.Page
TocTable.Update
End If

End Function
OnOpen Property for report
=InitToc()

OnPrint Property for group (partnumber) header
=UpdateToc([PartNumber],[Report])
 
M

Marshall Barton

We're going backwards ;-)

That message implies that the UpdateToc function can not be
found. Did you do something else to change things around.

S P E C I A L N O T E
Do not edit any code in the report's module while in break
mode (a line highlighted in yellow). Use Debug - Stop to
end code execution and switch the report back to design view
before editing anything in the module.
--
Marsh
MVP [MS Access]

I did as you suggested and am now getting error msg: Access can't find the
macro: '=UpdateToc(Nz([PartNumber], "Unknown Part"), [Report])'


"Marshall Barton" wrote
Try placing a break point on the first line in the UpdateToc
function (just clisk on the left margin of the line and it
will turn dark red when it's set). Then switch the report
to Preview and the code will stop when it hits the break
point. See what you can learn from stepping through from
there.
I've included the code I'm using.
Hopefully,
you will be able to tell why this won't work for me.

Option Compare Database

Dim db As DAO.Database
Dim TocTable As DAO.Recordset


Function InitToc()
Set db = CurrentDb()
db.Execute "Delete* From [Table Of Contents]"
Set TocTable = db.OpenRecordset("Table Of Contents", dbOpenTable)
TocTable.Index = "Description"

End Function

Function UpdateToc(TocEntry As String, Rpt As Report)
TocTable.Seek "=", TocEntry

If TocTable.NoMatch Then
TocTable.AddNew
TocTable!Description = TocEntry
TocTable![Page Number] = Rpt.Page
TocTable.Update
End If

End Function
OnOpen Property for report
=InitToc()

OnPrint Property for group (partnumber) header
=UpdateToc([PartNumber],[Report])
 
P

Pam

Marsh,

I didn't change anything. I clicked to the left on the first line of
UpdateToc and it changed the line to red and added a dot. I exited that
window and went to report preview and then the error msg popped up. I went
back and compared the code with what I copied form Northwind and all is
still the same.
Pam

Marshall Barton said:
We're going backwards ;-)

That message implies that the UpdateToc function can not be
found. Did you do something else to change things around.

S P E C I A L N O T E
Do not edit any code in the report's module while in break
mode (a line highlighted in yellow). Use Debug - Stop to
end code execution and switch the report back to design view
before editing anything in the module.
--
Marsh
MVP [MS Access]

I did as you suggested and am now getting error msg: Access can't find the
macro: '=UpdateToc(Nz([PartNumber], "Unknown Part"), [Report])'


"Marshall Barton" wrote
Try placing a break point on the first line in the UpdateToc
function (just clisk on the left margin of the line and it
will turn dark red when it's set). Then switch the report
to Preview and the code will stop when it hits the break
point. See what you can learn from stepping through from
there.
I've included the code I'm using.
Hopefully,
you will be able to tell why this won't work for me.

Option Compare Database

Dim db As DAO.Database
Dim TocTable As DAO.Recordset


Function InitToc()
Set db = CurrentDb()
db.Execute "Delete* From [Table Of Contents]"
Set TocTable = db.OpenRecordset("Table Of Contents", dbOpenTable)
TocTable.Index = "Description"

End Function

Function UpdateToc(TocEntry As String, Rpt As Report)
TocTable.Seek "=", TocEntry

If TocTable.NoMatch Then
TocTable.AddNew
TocTable!Description = TocEntry
TocTable![Page Number] = Rpt.Page
TocTable.Update
End If

End Function
OnOpen Property for report
=InitToc()

OnPrint Property for group (partnumber) header
=UpdateToc([PartNumber],[Report])
 
P

Pam

Marsh,

I've got it working and you're going to think I'm such a moron. The text
box for the field PartNumber was named Text68. When I changed the code to
read =UpdateToc([Text68], Report), it worked and I felt like an idiot for
overlooking it. I was reading the group header title on report design.

Thank you for your help and time. As always, it is greatly appreciated.
Pam

Marshall Barton said:
We're going backwards ;-)

That message implies that the UpdateToc function can not be
found. Did you do something else to change things around.

S P E C I A L N O T E
Do not edit any code in the report's module while in break
mode (a line highlighted in yellow). Use Debug - Stop to
end code execution and switch the report back to design view
before editing anything in the module.
--
Marsh
MVP [MS Access]

I did as you suggested and am now getting error msg: Access can't find the
macro: '=UpdateToc(Nz([PartNumber], "Unknown Part"), [Report])'


"Marshall Barton" wrote
Try placing a break point on the first line in the UpdateToc
function (just clisk on the left margin of the line and it
will turn dark red when it's set). Then switch the report
to Preview and the code will stop when it hits the break
point. See what you can learn from stepping through from
there.
I've included the code I'm using.
Hopefully,
you will be able to tell why this won't work for me.

Option Compare Database

Dim db As DAO.Database
Dim TocTable As DAO.Recordset


Function InitToc()
Set db = CurrentDb()
db.Execute "Delete* From [Table Of Contents]"
Set TocTable = db.OpenRecordset("Table Of Contents", dbOpenTable)
TocTable.Index = "Description"

End Function

Function UpdateToc(TocEntry As String, Rpt As Report)
TocTable.Seek "=", TocEntry

If TocTable.NoMatch Then
TocTable.AddNew
TocTable!Description = TocEntry
TocTable![Page Number] = Rpt.Page
TocTable.Update
End If

End Function
OnOpen Property for report
=InitToc()

OnPrint Property for group (partnumber) header
=UpdateToc([PartNumber],[Report])
 
M

Marshall Barton

That kind of mistake can be very difficult to notice. I
guess both of us should up the priority of double checking
the names of everything in the code being discussed.
--
Marsh
MVP [MS Access]

I've got it working and you're going to think I'm such a moron. The text
box for the field PartNumber was named Text68. When I changed the code to
read =UpdateToc([Text68], Report), it worked and I felt like an idiot for
overlooking it. I was reading the group header title on report design.

That message implies that the UpdateToc function can not be
found. Did you do something else to change things around.

S P E C I A L N O T E
Do not edit any code in the report's module while in break
mode (a line highlighted in yellow). Use Debug - Stop to
end code execution and switch the report back to design view
before editing anything in the module.
 

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