473,396 Members | 1,827 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,396 software developers and data experts.

report listed in combo box

68 64KB
Hi,
I have an Access 2007 database with a form called 'Report Menu'. I would like to create a combo box that shows all the reports in the report as a dropdown. I would also like to include on that form, a button that, will preview the selected report from the combo box, when clicked.
I will appreciate if anyone can help me out on this.
Thanks.
Oscar
Jun 25 '12 #1
8 2051
ADezii
8,834 Expert 8TB
The following Code, placed in the Open() Event of your Form, will populate a Combo Box named cboReports with all the Reports in your Database. The rest is relatively easy to accomplish.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. Dim obj As AccessObject
  3. Dim objApp As Object
  4. Dim strRpts As String
  5.  
  6. Me![cboReports].RowSourceType = "Value List"
  7.  
  8. Set dbs = Application.CurrentProject
  9.  
  10. If dbs.AllReports.Count = o Then Exit Sub
  11.  
  12. 'Search for ALL AccessObject objects in AllReports collection.
  13. For Each obj In dbs.AllReports
  14.   'Me![cboReports].AddItem obj.Name   'Alternative approach
  15.    strRpts = strRpts & obj.Name & ";"
  16. Next obj
  17.  
  18. 'Populate Combo Box with List of all Reports in the Database. 
  19. 'Remove Trailing ";", (Not  necessary if using AddItem)
  20.  Me![cboReports].RowSource = Left$(strRpts, Len(strRpts) - 1)
  21. End Sub
Jun 25 '12 #2
Stoic
68 64KB
@ADezii
Hi ADezii,
Thanks again. This is working perfectly well, but I still need your help on the button the previews the report.
Thanks
Jun 25 '12 #3
Mihail
759 512MB
Under _Click event place one of the following line:

Expand|Select|Wrap|Line Numbers
  1. 'To preview:
  2. DoCmd.OpenReport "ReportName", acViewReport
  3.  
  4. 'To print:
  5. DoCmd.OpenReport ("ReportName")
  6.  
  7. 'To save as .rtf :
  8. DoCmd.OutputTo acOutputReport, "ReportName", "RichTextFormat(*.rtf)", , True
Jun 26 '12 #4
ADezii
8,834 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1. If IsNull(Me![cboReports]) Then Exit Sub
  2.  
  3. 'To Open the selected report in Preview Mode
  4. DoCmd.OpenReport Me![cboReports], acViewPreview
Jun 26 '12 #5
Stoic
68 64KB
@ADezii
Thanks again ADezii, I am very grateful.
Jun 27 '12 #6
Stoic
68 64KB
@Mihail
Thanks Mihail, but this is not what I wanted.
Cheers!
Jun 27 '12 #7
Stoic
68 64KB
@ADezii
Hi ADezii,
I just want to thank you for your brilliant answer to my question on populating my reports to a combo box on my form. It works very well.

I also have a problem with my dlookup. I have developed an entry form with a combo box it containing a list of school codes. I would like to populate other details from the school table to the fields on the form for data entry purpose. This is what I have so far but is not working:

Me.SName = DLookup("[SchoolName]", "tblSchools", "[cboSchoolCode]='" & Me.[cboSchoolCode] & "'")

Me.txtCounty = DLookup("[County]", "tblSchools", "[cboSchoolCode]='" & Me.[cboSchoolCode] & "'")

But this is not just working.
Thanks for your assistance.
Oscar
Jun 27 '12 #8
ADezii
8,834 Expert 8TB
Assuming School Codes are String Values, your problem lies in the WHERE Clause of DLookup(). You need to reference the 'Name' of the [School Code] Field in tblSchools, and not the Name of the Combo Box. Some examples 'may' be:

Expand|Select|Wrap|Line Numbers
  1. Me.SName = DLookup("[SchoolName]", "tblSchools", "[SchoolCode]='" & Me.[cboSchoolCode] & "'")
  2.  
  3. Me.SName = DLookup("[SchoolName]", "tblSchools", "[School Code]='" & Me.[cboSchoolCode] & "'")
Jun 27 '12 #9

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

Similar topics

3
by: RWC | last post by:
Hello, I have an issue that's driving me batty! I have a report, whose record source is SQL based on a normalized set of tables. There are no nested queries and no dlookups in this record...
1
by: allie357 | last post by:
I am trying to add a form with a combo box to an existing parameter query report. I followed the directions from this link:http://office.microsoft.com/en-us/assistance/HA011170771033.aspx ...
9
by: DeeMing | last post by:
I have created a form in Access, similar to a switchboard in which I want to print reports, and I can do this. However, I want to print based on particular parameters; i.e. I have 2 combo boxes on...
3
by: ncsuwolfe | last post by:
Greetings, I am creating a frequency report. I have 41 records, each record has sub-records from a source table. I am trying to detemine the frequency that each sub-record appears in a main...
1
by: CARINA | last post by:
Please help ! I am very new. I made a report in access 2003 and want to add a combo box where i can select from several options without typing it. when i print the report the combo box and its...
3
by: jambonjamasb | last post by:
Hi I have two tables: email_tbl Data_table Data table is is used to create a Form Data_form
30
by: vanlanjl | last post by:
Question: How do I create a Report based off the values/selections of mutliple combo boxes in a form? I have tried this several times with several failures and have used multiple codes to try...
10
by: BeaBea | last post by:
Hi All, I have been reading some of the threads in your forum and decided to join and post my question. Hopefully it won't be too lengthy. I have created an Unbound Form called paramform2. ...
2
by: guinb | last post by:
i have a form with 2 boxes for start date and end date as well as 2 combo boxes for serial number and aircraft type. if i select a specific value for each then the rerport is generated just fine but...
3
by: MDay | last post by:
Good morning, I would like to use an unbound combo box on a form to preview the selected report. The combo box is populated by a list of all the report names. I am currently using the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.