Error "on the fly" report

2wistd

Registered User.
Local time
Today, 16:10
Joined
Jan 17, 2013
Messages
66
I've followed this PDF to create reports on the fly. http://www.grbps.com/access4.pdf

The process is what i am looking for atleast to start out. Problem is i've done this in my project and tried to do it on its own and I get an error both ways.

"Application-defined or object-defined error"
or Runtime error 2465.

I'd really like to be able to allow the user to create their own "custom" reports, and I've not figured out another way to do it.

Thanks for any advice.
 
Code:
[FONT=Tahoma][SIZE=1][FONT=Tahoma][SIZE=1]
[LEFT]Sub MakeReport()
On Error GoTo Err_MakeReport[/LEFT]
[/SIZE][/FONT][/SIZE][/FONT][FONT=Tahoma][SIZE=1][COLOR=#008100][FONT=Tahoma][SIZE=1][COLOR=#008100][FONT=Tahoma][SIZE=1][COLOR=#008100][LEFT]'Open report in design view to write properties to objects[/LEFT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Tahoma][SIZE=1][FONT=Tahoma][SIZE=1][LEFT]DoCmd.OpenReport "rptCustom", acDesign[/LEFT]
[/SIZE][/FONT][/SIZE][/FONT][FONT=Tahoma][SIZE=1][COLOR=#008100][FONT=Tahoma][SIZE=1][COLOR=#008100][FONT=Tahoma][SIZE=1][COLOR=#008100][LEFT]'Read combo box selections and use subroutine to set report object properties[/LEFT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Tahoma][SIZE=1][FONT=Tahoma][SIZE=1][LEFT][COLOR=red]SetReportControls Forms!frmChooseFields.cboField1.Value, Reports!rptCustom.lblField1, Reports!rptCustom.tbField1[/COLOR]
SetReportControls Forms!frmChooseFields.cboField2.Value, Reports!rptCustom.lblField2, Reports!rptCustom.tbField2
SetReportControls Forms!frmChooseFields.cboField3.Value, Reports!rptCustom.lblField3, Reports!rptCustom.tbField3
SetReportControls Forms!frmChooseFields.cboField4.Value, Reports!rptCustom.lblField4, Reports!rptCustom.tbField4[/LEFT]
[/SIZE][/FONT][/SIZE][/FONT][FONT=Tahoma][SIZE=1][COLOR=#008100][FONT=Tahoma][SIZE=1][COLOR=#008100][FONT=Tahoma][SIZE=1][COLOR=#008100][LEFT]'Close design view without prompting to save changes[/LEFT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Tahoma][SIZE=1][FONT=Tahoma][SIZE=1][LEFT]DoCmd.Close acReport, "rptCustom", acSaveYes[/LEFT]
[/SIZE][/FONT][/SIZE][/FONT][FONT=Tahoma][SIZE=1][COLOR=#008100][FONT=Tahoma][SIZE=1][COLOR=#008100][FONT=Tahoma][SIZE=1][COLOR=#008100][LEFT]'Open finished report in preview view[/LEFT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Tahoma][SIZE=1][FONT=Tahoma][SIZE=1][LEFT]DoCmd.OpenReport "rptCustom", acPreview
Exit_MakeReport:
Exit Sub
Err_MakeReport:
MsgBox Err.Description
Resume Exit_MakeReport
End Sub
 
Sub SetReportControls(varFieldName As Variant, conLabel As Control, conTextBox As Control)[/LEFT]
[/SIZE][/FONT][/SIZE][/FONT][FONT=Tahoma][SIZE=1][COLOR=#008100][FONT=Tahoma][SIZE=1][COLOR=#008100][FONT=Tahoma][SIZE=1][COLOR=#008100][LEFT]'Check if selection is 'null'[/LEFT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Tahoma][SIZE=1][FONT=Tahoma][SIZE=1][LEFT]If IsNull(varFieldName) Then [/SIZE][/FONT][/SIZE][/FONT][FONT=Tahoma][SIZE=1][COLOR=#008100][FONT=Tahoma][SIZE=1][COLOR=#008100][FONT=Tahoma][SIZE=1][COLOR=#008100]'Blank out the relevant objects[/LEFT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Tahoma][SIZE=1][FONT=Tahoma][SIZE=1][LEFT]conLabel.Caption = " "
conTextBox.ControlSource = ""
Else [/SIZE][/FONT][/SIZE][/FONT][FONT=Tahoma][SIZE=1][COLOR=#008100][FONT=Tahoma][SIZE=1][COLOR=#008100][FONT=Tahoma][SIZE=1][COLOR=#008100]'Write the selected field name to the appropriate objects[/LEFT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Tahoma][SIZE=1][FONT=Tahoma][SIZE=1][LEFT]conLabel.Caption = varFieldName
conTextBox.ControlSource = varFieldName
End If[/LEFT]
End Sub
[/SIZE][/FONT][/SIZE][/FONT]

The red line is the first error, I am sure the other 3 would be errors too.
 
Where do you have this code? The code should go in a Standard module.. Not behind a Report or Form..

attachment.php
 
Yes, the code is in a module, and a button on the form 'frmChooseFields" calls the function.
 
So could you show the Code behind the button?

Also did you try stepping through your code, to find exactly where that your code fails??

attachment.php
 
The button code is simply:
Code:
    MakeReport

I tried to go line by line, but I continue to get the same error, and I am not sure what I can do to get more information than that.

Thank you for trying to help.
 
Okay, I figured it out. When I was creating my report, I was putting the name to the label, but not actually naming the label itself. Once I named every object correctly it worked. :banghead::banghead:
 

Users who are viewing this thread

Back
Top Bottom