×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

2451 Runtime error with DoCmd.OpenReport

2451 Runtime error with DoCmd.OpenReport

2451 Runtime error with DoCmd.OpenReport

(OP)
I have a button on my form that prints a report and one that previews the report.  The preview report button works perfectly, but the print button gives a 2451 runtime error. The code for each button is exactly the same with the exception of the DoCmd.OpenReport stDocName, acPreview and DoCmd.OpenReport stDocName, acNormal.

See the attached file for code.

RE: 2451 Runtime error with DoCmd.OpenReport

I don't have time to look it up; what is the Err.Description for 2451?

"Teamwork means never having to take all the blame yourself."
 

RE: 2451 Runtime error with DoCmd.OpenReport

(OP)
It is:
"The report REPORTNAME you entered is misspelled or refers to a report that isn't open or doesn't exist."

REPORTNAME Changes dependent on which report I am trying to open.

RE: 2451 Runtime error with DoCmd.OpenReport

Well for starters, the constants you need are acViewPreview & acViewNormal, not just "acPreview" & "acNormal".
Maybe that will help?

"Teamwork means never having to take all the blame yourself."
 

RE: 2451 Runtime error with DoCmd.OpenReport

(OP)
Thanks, but it did not help.  When I click on the print button, it prints as the error message pops up, but it does not filter the results.

RE: 2451 Runtime error with DoCmd.OpenReport

Assuming School is a field name, this might be incorrect syntax:

Quote:


Case "ISURHIT"
strWhere = strWhere & "([School] = ""ISU"" OR [School] = ""RHIT"") AND "

This is not incorrect - enclose string literals in single quotes:

CODE

Case "ISURHIT"
strWhere = strWhere & " School = 'ISU' OR School = 'RHIT' AND "

Is this by any chance a first effort?
 

"Teamwork means never having to take all the blame yourself."
 

RE: 2451 Runtime error with DoCmd.OpenReport

(OP)
Yes this is my first go at a database of this size and scope.

School is a field name on the table to which the report refers.

If it is incorrect syntax, why does it work correctly?  

RE: 2451 Runtime error with DoCmd.OpenReport

Could be "" is interpreted as " & "?
A good starting place is here:
http://www.justphukit.com/sql/sql-tutorials-1.php

Also an Access help search on concatenating strings would be helpful. My head is full & I'm outta here (and now that I look at the snippet I posted it looks odd, too). I'll try & return tomorrow & see what's transpired. Good luck!

"Teamwork means never having to take all the blame yourself."
 

RE: 2451 Runtime error with DoCmd.OpenReport

I would say that your problem is here:

            stDocNafrm = "Sacrafrmnts"

I also wonder if Grad Year is a text field?

RE: 2451 Runtime error with DoCmd.OpenReport

I think this one has at least one or two errors, just guessing at the data types and all:

CODE

    If Not IsNull(Me.txtYear) Then
        strWhere = strWhere & "[Grad Year] = """ & Me.txtYear & """ AND "
    End If

I think it SHOULD be:

CODE

    If Not IsNull(Me.txtYear) Then
        strWhere = strWhere & " " & TableName.[Grad Year] & "= '" & Me.txtYear & "'" AND "
    End If

Or similar.  That might not be the absolute correct, but I'm not putting it in to test it right now.  There, I changed your use of double quotes to single quotes, which may not be what you're after either.  Also, if [Grad Year] is a field name of a table, then it should have the table name and field name, but not inside of quotes, or else Access just sees that as text.  If it's a field on the form, then you need just the field name (again, not inside quotes).

'Course, I could be missing something altogether, but that looks like a problem spot to me.

--

"If to err is human, then I must be some kind of human!" -Me

RE: 2451 Runtime error with DoCmd.OpenReport

The problems with the SQL would not produce " .. REPORTNAME you entered is misspelled ..", whereas:

stDocNafrm = "Sacrafrmnts"

Is almost certainly misspelt.

RE: 2451 Runtime error with DoCmd.OpenReport

(OP)
BTW, I should mention that I am using Access 97.  I will try the suggestions above next week and let you know how it pans out.  Thank you for all the help!

RE: 2451 Runtime error with DoCmd.OpenReport

In particular, check the spelling of Sacraments, it does not have an 'f'.

RE: 2451 Runtime error with DoCmd.OpenReport

(OP)
Remou, I cannot find that misspelling anywhere in the code.

Perhaps I should explain in more detail what this is doing.  This is a form with a bunch of checkboxes and a few textboxes that are used to create a filter string to apply to different reports based on what the user selects to filter.  For example, if a user wants to see all the people in the database that are eucharistic ministers and lectors, they will check the appropriate checkboxes and click on view report.  The Ministry report should open with only the eucharistic ministers and lectors.  All of my reports reference the same table.  

Grad year and hometown are text boxes the rest are checkboxes.  

I remember trying to use single quotes before and it would not work properly, but when I used double quotes it worked.

When I open a report in acViewNormal, does it automatically close the report or does it work like acViewPreview?  The way this is reacting it leads me to believe that it opens the report, prints it, closes the report and moves to the next line, which cannot be processed because the report is now closed.  Is this the way it works?  If so, how can I open the report, apply a filter and print it with one button?
 

RE: 2451 Runtime error with DoCmd.OpenReport

You show this section in your code:

CODE

        If frm.chkIsLector = -1 Or frm.chkIsEucharistic = -1 Or frm.chkIsServer = -1 Or frm.chkIsHospitality = -1 Or frm.chkIsMusic = -1 Or frm.chkIsReligious = -1 Then
            stDocNafrm = "Ministry"
            DoCmd.OpenReport stDocNafrm, acPreview
            Reports!Ministry.Filter = strWhereMinistry
            Reports!Ministry.FilterOn = True
        End If
        If frm.chkIsFaith = -1 Or frm.chkIsPrayer = -1 Or frm.chkIsService = -1 Or frm.chkIsSocial = -1 Or frm.chkIsWorship = -1 Then
            stDocNafrm = "Interests"
            DoCmd.OpenReport stDocNafrm, acPreview
            Reports!Interests.Filter = strWhereInterest
            Reports!Interests.FilterOn = True
        End If
        If frm.chkNeedConfirmation = -1 Or frm.chkNeedEucharist = -1 Or frm.chkNeedReconciliation = -1 Or frm.chkNotCatholic = -1 Then
            stDocNafrm = "Sacrafrmnts"
            DoCmd.OpenReport stDocNafrm, acPreview
            Reports!Sacrafrmnts.Filter = strWhereSacrafrmnts
            Reports!Sacrafrmnts.FilterOn = True
        End If
        If Not IsNull(frm.txtHofrmtown) Then
            stDocNafrm = "Hofrmtown"
            DoCmd.OpenReport stDocNafrm, acPreview
            Reports!Hofrmtown.Filter = strwhere
            Reports!Hofrmtown.FilterOn = True
        End If
        'if special boxes are checked or hofrmtown is filled in do not create the all report
        If Not IsNull(frm.txtHofrmtown) Or frm.chkIsLector = -1 Or frm.chkIsEucharistic = -1 Or frm.chkIsServer = -1 Or frm.chkIsHospitality = -1 Or frm.chkIsMusic = -1 Or frm.chkIsReligious = -1 Or frm.chkIsFaith = -1 Or frm.chkIsPrayer = -1 Or frm.chkIsService = -1 Or frm.chkIsSocial = -1 Or frm.chkIsWorship = -1 Or frm.chkNeedConfirmation = -1 Or frm.chkNeedEucharist = -1 Or frm.chkNeedReconciliation = -1 Or frm.chkNotCatholic = -1 Then
        'do nothing
        Else
            stDocNafrm = "All"
            DoCmd.OpenReport stDocNafrm, acPreview
            Reports!All.Filter = strwhere
            Reports!All.FilterOn = True
        End If
    End If

Ministry and Interests are normal, then you have Sacrafrmnts, which may be the name of your report, but then again it may not be. It would be useful to step through the code and check on which line the error is occuring. It is possible that a report is not opening, I guess.
 

RE: 2451 Runtime error with DoCmd.OpenReport

(OP)
I see what you are talking about now, it looks like you ran a replace and replaced all the "Me" to "frm" which would change the "me" in sacraments  to "frm".  If you look at the original code in the attachment, you will notice that it is spelled correctly.

As it has been years since I took a programming class, I have forgotten how to step through the code.  Please, jog my memory.

Thanks again for all the tips.

RE: 2451 Runtime error with DoCmd.OpenReport

blush Apologies, I replace Me to step without a form, but that is a poor excuse :)

However, it still seems likely that a report name is misspelt.

You can step through the code by setting a breakpoint (F9 to toggle) and then pressing F8 to run each line.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close