+ Reply to Thread
Results 1 to 9 of 9

Run time error '3071' on open report vba code

  1. #1
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Run time error '3071' on open report vba code

    Hi,

    I have written a macro in Access VBA which executes a DCount on a query and if the DCount is above 1 it opens and prints a report. However when it gets to the line of code which opens the report it stops and debugs producing an error of "run time error 3071: This expression is typed incorrectly, or it is too complex to be evaluated"

    The code I have created is below and I have highlighted the line it debugs on in red:
    Please Login or Register  to view this content.
    I have tried reducing it because at first I had
    Please Login or Register  to view this content.
    However it kept producing that error.Does anyone know why it keeps debugging on that line?

    Thanks,

    jeskit
    Last edited by jeskit; 06-11-2012 at 05:06 AM.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Run time error '3071' on open report vba code

    can you open the report normally?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2403 Win 11 Home 64 Bit
    Posts
    23,810

    Re: Run time error '3071' on open report vba code

    I wonder if you have to reference your query in your docmd line.

    http://msdn.microsoft.com/en-us/library/ff192676.aspx

    Alan
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Run time error '3071' on open report vba code

    Hi,

    Thank you for replying....Yes I can open it normally.

    alansidma....I don't really want the query referenced with the open report line because I am just using the query to find out how many records there. The query is more a Count than anything as It counts how many records there are and If the count returns more than 0 then I want to open the report and if it returns 0 then show a message saying there are no records to run the report.

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Run time error '3071' on open report vba code

    does it help if you use number variables instead of string?

  6. #6
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Run time error '3071' on open report vba code

    Hi,

    I tried changing it to a number variable instead and it still debugs on the open report line and produces the same error

  7. #7
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Run time error '3071' on open report vba code

    Hi
    I just tried running the macro with all lines except the open report line commented out and still debugged and produced the error. Would the problem be that I have the report running on a query so when it opens a runs a query to produce the results?

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Run time error '3071' on open report vba code

    it's probably help to see the db if possible. what is the source query for the report? are there any parameters or filters being applied?

  9. #9
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Run time error '3071' on open report vba code

    Hi

    Thank you for all your help however I have solved the problem. The report I was trying to open had a filter on the data, so I took that out and in the VBA code I add a where clause to the Open report line and NOW it not only opens without a debuggig it gets the correct reuslts and prints the report.

    Thank you for anyone's help i greatly appreciate all of it!!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1