Creating Reporting Form

cfp76

Registered User.
Local time
Today, 22:35
Joined
Aug 2, 2001
Messages
42
I have my database built - ready to begin the reports. What I want to do is have a report screen (will not be needing criteria) that has a drop down list box that will show all reports - from that list the person can pick a report and then either print or preview it. I also want an option that they can print all the reports available.

I just have no idea where to start on this... any suggestions?

cfp
 
Literally "where to start"? =) If that's the case, then I would start by making a Form and placing a Combo Box and two buttons (print and preview) on it, then setting the row source of the combo as whichever reports you want along with an "All". Do you know anything about Visual Basic?
 
Yes.. I know VB but I'm rusty....

I have my combo box but when I do my print button, I do not know the command on how to set the value of the report to print to that of what was selected in the combo box.

If they choose report 4 from list, and I hit print - how do I make the print button recognize I want report 4?

cfp
 
Ok, this is regarding your other post on populating the Combo with all your reports too.

I set a variable to hold whatever is selected in the combo box. I looked in the help file and found a reference and example for using AllReports. So I came up with the code in the Form Open event (VB). For the On Change event of the combo box, I set whatever is selected to the varRptName. Then for each of the buttons' On Click events, I open a report for print or preview. Here's the code I have:
Code:
Option Compare Database
Dim varRptName As String
Dim obj As AccessObject, dbs As Object

Private Sub Form_Open(Cancel As Integer)
  Set dbs = Application.CurrentProject
  For Each obj In dbs.AllReports
    Me.MyCombo.RowSource = Me.MyCombo.RowSource & obj.Name & ";"
  Next obj
End Sub

Private Sub MyCombo_Change()
  varRptName = Me.MyCombo.SelText
End Sub

Private Sub btnPrint_Click()
  Dim msg
  msg = MsgBox("Do you want to print all reports?", vbYesNoCancel)
  If msg = vbYes Then
    Set dbs = Application.CurrentProject
    For Each obj In dbs.AllReports
      DoCmd.OpenReport varRptName, acViewNormal
    Next obj
  ElseIf msg = vbNo Then
    DoCmd.OpenReport varRptName, acViewNormal
  Else
    Exit Sub
  End If
End Sub

Private Sub btnPreview_Click()
  DoCmd.OpenReport varRptName, acViewPreview
End Sub
Hope this helps.

Edit: I altered btnPrint_Click() to give an option of printing all reports.
Edit: Oops, I also moved some variables outside the sub.
 
Last edited:
this is the print button code:

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

Dim stDocName As String

stDocName = Comboxname.Value

DoCmd.OpenReport stDocName, acNormal

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub

This is the preview button code:

Private Sub Command1_Click()
On Error GoTo Err_Command1_Click

Dim stDocName As String

stDocName = Comboxname.Value

DoCmd.OpenReport stDocName, acPreview

Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click

End Sub
The only thing to work at is how All will print all reports code
above will print or preview reports by select names from a
combo box

I got you almost what you need
 
Last edited:
This is great - thank you both very much

Boy - it has been a long time since I sat through a VB class - long time ago in a galaxy very far away (and I don't think I was awake for half of it LOL)

thanks again!

crystal
 
well.....

now I'm becoming a pest....

I set up the print button and all seemed to work till I added a report.

I added it to my table and it did show on my combo box list - selected it..... and when I hit print, I got the other report.

any suggestions as to what I did wrong?
 
I added a new test report, opened my form, selected the new report, and previewed it. Everything worked fine. :( What do you mean you added it to your table? You added the report to the table? I don't understand.

Edit: You're not a pest =P This forum is to help people and you need some help. =)
 
I would think that cfp means added the name to the table,

was it a refresh problem by not showing? after adding to
table did you reopen form and then the dropdown?
 
Why would you add a report name to a table? She said that the new report did display in the combo. The code behind the print button called the wrong report.
 
For my combo box I have a table that feeds what drops down - the table includes the actual name of the report and then the description I want the user to see....

ack - I am a pest LOL

I create the report then add it to the tblReports table so it will show in my dropdown - not a refresh issue as the name was there...

I think I'm trying to incorporate too many methods of getting the same results - melding them together when they cannot be.... so I'm getting a hodge podge.

blah
 
Last edited:
Ah, I see. I am using exactly what I have posted above. Any time you add a new report, you won't have to do anything else. The code automatically retrieves all report names in your database. You might give it a shot to see if it works for you.

You might also look in the help file for 'AllReports' to view the AllReports Collection and an example of it.
 
so.... I would wipe out my form completely - and create this code instead?...

I'm normally not this dense.. my apologies.
 
cfp,

no dont wipe out your form but if I understand how Tiro
code is working you do not need a table with the report
names....


Tiro has code for a print button, preview button
and the combobox and the form....take
all of Tiro code and place in the form and rename
your buttons and combo box should do it.
 
Last edited:
No need for apologies =) It's a boring day at work anyway HA! =D

I have code for 4 events: 1-when the form is opened, 2-when something is selected in the combo box, and 3,4-when each of the buttons is clicked.

To put the code into those events, you need to open the form in design view. In the case of the event when the form opens, you need to have the form selected (click on that square button at the top left of the form) then in the Properties under the Events tab, there will be an "On Open" field. This will work correctly if there's nothing in "On Open". Click in the field then click on the "..." button to the right of the field. You then want to select "Code Builder" and it will take you to the VB window. You can also get to that window by going to View -> Code on the main menu.

Once you're there, it will have already started some of the code I've posted. You should be able to paste my code over the code that's there and substitute the names of your combo box and buttons for mine. If you return to the form in design view, the On Open event of the form will now say [Event Procedure], meaning that it will execute any code that is there. Make sure that the On Change and On Click events for the combo box and buttons (respectively) also say [Event Procedure]. It should work after that.

Sorry if any of this is confusing. If it is, I'll try to remedy it.
 
Last edited:
You're right, the Print All currently does not work. I hadn't tested it since I hate killing trees =P I'll try to fix it.
 
Hehe, clumsy error. You need to change
Code:
Private Sub btnPrint_Click()
  Dim msg
  msg = MsgBox("Do you want to print all reports?", vbYesNoCancel)
  If msg = vbYes Then
    Set dbs = Application.CurrentProject
    For Each obj In dbs.AllReports
      DoCmd.OpenReport [b]varRptName[/b], acViewNormal
    Next obj
  ElseIf msg = vbNo Then
    DoCmd.OpenReport varRptName, acViewNormal
  Else
    Exit Sub
  End If
End Sub
to
Code:
Private Sub btnPrint_Click()
  Dim msg
  msg = MsgBox("Do you want to print all reports?", vbYesNoCancel)
  If msg = vbYes Then
    Set dbs = Application.CurrentProject
    For Each obj In dbs.AllReports
      DoCmd.OpenReport [b]obj.Name[/b], acViewNormal
    Next obj
  ElseIf msg = vbNo Then
    DoCmd.OpenReport varRptName, acViewNormal
  Else
    Exit Sub
  End If
End Sub
varRptName didn't change with each new object. :o
 
Tiro,

I just tested your code and it works great....
your code does also gives the option to print all reports
you do have to make sure you have a
combo box and two buttons and then name them right
but it covers every things cfp wants
 
Did I ever mention how wonderful you guys are hehehe

Sheesh - gonna put it into affect now - so.... it would be helpful for me to name my report something less......... ugly?

Boy - where would I be without you guys - oh.... report selection-less

THANK YOU AGAIN!

cfp
 
well - I am still lacking - but thank you all for trying. I guess it's just not going to happen for me.

thanks though - you all are very helpful
 

Users who are viewing this thread

Back
Top Bottom