Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open report if no form exists

Status
Not open for further replies.

Tadynn

Technical User
Oct 8, 2001
72
AU
Hi all,

Access 2k

I've created a form that contains a list of all reports in my database and all forms that are associated with the reports. This information is contained in a table called tbl_Reports and I use the MSysObjects to get the information on both reports and forms contained in the db.

The forms is a continuous form that list all the records in the tbl_reports table. I've inserted a button into every line that opens up whatever form is associated with that report. This works okay.

The problem I am having, is that some of my reports do not require any parameters so a form is not required. I wrote the following if statement that checks if the report has a form, and if it doesn't then just go straight to opening up the report but I always get an invalid use of null because there is the FormName field is blank.

Can anyone see where I am going wrong?


Dim FName As String
Dim RName As String

' FormName is the name of the form
FName = Forms!frm_ReportsSub!FormName
' ReportCode is the name of the report
RName = Forms!frm_ReportsSub!ReportCode

If IsNull(FName) Then 'Check if FormName is blank
DoCmd.OpenReport RName 'If it is then open the report instead
Else
DoCmd.OpenForm FName 'If not then open the form
End If


Thanks, Tadynn


 
Try putting in a break to check the value of FName while debugging. Maybe it's something other than Null.
 
Try:
Code:
FName = Nz(Forms!frm_ReportsSub!FormName,"")
.
.
.
If FName = "" then 'Check if FormName is blank
The problem is that you cannot assign the value Null to a String.

If you had defined FName as a Variant it would have worked.

The Nz function is built in and was provided because this sort of problem is very common when retrieving data from tables and objects.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top