473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Error using script to select and print reports in Access 2007

copied and pasted following script into command button click event:
Private Sub PrintReport_Click()
If Not IsNull(ComboReports) And ComboReports <> "" Then
DoCmd.OpenReport ComboReports, acViewPreview ' use acNormal to print without preview
Else
MsgBox ("You Must First Select a Report To Print!")
ComboReports.SetFocus
End If
ComboReports = ""
End Sub

get error when clicking button:
Microsoft Office Access can't find the object 'Private Sub PrintReport_Click()
Jun 2 '16 #1
8 1001
PhilOfWalton
1,430 Expert 1GB
What is the name of your command button?

The VBA can be tidied up thus

Expand|Select|Wrap|Line Numbers
  1. If ComboReports > "" Then
  2.    DoCmd.OpenReport ComboReports, acViewPreview ' use acNormal to     print without preview
  3. Else
  4.    MsgBox ("You Must First Select a Report To Print!")
  5. ComboReports.SetFocus
  6.  
I am assuming that the ComboReports is being populated from the database list of reports, rather than a table of report names. If the latter is true, be warned that the selected report may not exist.
Phil
Jun 2 '16 #2
Thanx for your response

The combobox button seems to be working and listing the reports.

The name of the command button is PrintReport.
Jun 2 '16 #3
PhilOfWalton
1,430 Expert 1GB
It's got me foxed.
Does the program compile without errors?
Is there an [Event Procedure] on the On Click of the PrintReport button?
if you click on the 3 dots at the end of the On Click, is the code exactly as posted?

It might be worth deleting your code and setting the [Event Procedure] up again and copying in the code I gave you above

Phil
Jun 2 '16 #4
Thanx again.

I followed the instructions and copied the scripts from an earlier BYTES.com posting.

I replaced the original script with the one you sent above.

I still get the error. It appears the PrintReport command button is not recognizing the ComboReports selection.
Jun 3 '16 #5
PhilOfWalton
1,430 Expert 1GB
2 further thoughts.
Put a breakpoint on the Sub PrintReport_Click() line and step through to see exactly where the error occurs.
Let us know the exact message

If, as you suspect, it can't find the report, don't forget it will be looking at the data in the Bound Column of your Combo Box.
So we need to know the Row Source of your Combo, the Bound Column and the Column Widths. I'm guessing that Report Name is not the bound column.

Phil
Jun 3 '16 #6
I think I see my problem - the combobox is unbound not bound.
Jun 3 '16 #7
PhilOfWalton
1,430 Expert 1GB
Shouldn't matter.

If you don't answer the questions, you can't expect further help.

Phil
Jun 3 '16 #8
Thanx for your help - I will find a work around
Jun 3 '16 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: SandySailer | last post by:
It's been years since I've created a macro in MS Access (I am a ColdFusion programmer now), but I need to do some work in an Access database. I searched for an answer but couldn't find it, so that's...
2
Walt in Decatur
by: Walt in Decatur | last post by:
Just tried to open reports in a database prepared in Access 2003 in my brand new Access 2007 and got this error. One of these reports has sub-reports that generate this error, but another one does...
2
by: Constantine AI | last post by:
I am wanting to import CSV files into Access, which isn't a problem at the moment the code i have is as follows: Dim strSQL As String Dim CSVTable As String Dim FilePath As String Dim Result As...
2
by: sphinney | last post by:
Hi everyone. I have a form in my Access 2007 database with a Microsoft Office Document Imaging Viewer Control 12.0 object on it. The object is named "GRAPHIC_mdv". When the form opens I want to...
2
anoble1
by: anoble1 | last post by:
I use a database that has query that pulls the user's current NTID or name. Here is what my query says: Environ("UserName") Worked on offce 2003, since I switched the Environ is not valid. How...
7
by: ncsthbell | last post by:
I am importing a lot of data from spreadsheets and 'import error' tables are being created. I need to be able to delete these tables using vba code in the database. Also, each of the tables are...
5
by: Andrew Shearer | last post by:
I have hit the 2GB limit in Excel and am now looking at a solution in Access 2007. The issue I'm facing is replicating what I'm doing in Excel into Access. The main challenge and my question is how...
1
by: Scorp Scorp | last post by:
Dear All, I designed a report, and bound with some data, the retreived data is 7 coloumns. I set a buttong to open the report in print preview, also to show display the page in landscape. Now on...
4
by: NiallP17 | last post by:
Hi, I am having trouble storing the values into the 3 variables. I believe I must have done something wrong but I have looked online and cannot find a solution. Any help would be kindly appreciated....
2
by: Vihanga | last post by:
Hi, I am a beginner in programming and am trying to write code to delete a record from a table using a record... Can someone help me in writing it? Thanks
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.