will not eval a function name from a table.

B

bipin

Hello,

I have a table of reports and the functions that must run
before the report is opened.

Set db = DBEngine(0)(0)
sSQL = "SELECT DISTINCTROW tblReportSelect.CompanyID, " & _
"tblReports.ReportID, tblReports.ReportName, " & _
"tblReports.ActualName, tblReports.FuncName " & _
"FROM tblReportSelect INNER JOIN tblReports ON " & _
"tblReportSelect.ReportID = tblReports.ReportID " & _
"WHERE (((tblReportSelect.CompanyID)=" & [Forms]!
[frmReports]![cboComp] & "));"

Set rsReports = db.OpenRecordset(sSQL, dbOpenSnapshot)

Do Until rsReports.EOF
If Not IsNull(rsReports!FuncName) Then
Debug.Print rsReports!FuncName
' errors here:
Eval (rsReports!FuncName)
End If

DoCmd.OpenReport (rsReports!ActualName), A_NORMAL ' A_PREVIEW
DoEvents
rsReports.MoveNext
Loop
rsReports.Close

now the eval function will not run the function. the same code works
fine
in AC97. but in AC2007 i get the following error:

Run-time error '2482':

Microsoft Office Access can't find the name 'ClassMerchPrep' you
entered
in the expression.

the function runs fine outside of the eval function. Are there any
alternatives
to the eval function?

Thanks,

Bipin
 
D

Dirk Goldgar

bipin said:
Hello,

I have a table of reports and the functions that must run
before the report is opened.

Set db = DBEngine(0)(0)
sSQL = "SELECT DISTINCTROW tblReportSelect.CompanyID, " & _
"tblReports.ReportID, tblReports.ReportName, " & _
"tblReports.ActualName, tblReports.FuncName " & _
"FROM tblReportSelect INNER JOIN tblReports ON " & _
"tblReportSelect.ReportID = tblReports.ReportID " & _
"WHERE (((tblReportSelect.CompanyID)=" & [Forms]!
[frmReports]![cboComp] & "));"

Set rsReports = db.OpenRecordset(sSQL, dbOpenSnapshot)

Do Until rsReports.EOF
If Not IsNull(rsReports!FuncName) Then
Debug.Print rsReports!FuncName
' errors here:
Eval (rsReports!FuncName)
End If

DoCmd.OpenReport (rsReports!ActualName), A_NORMAL ' A_PREVIEW
DoEvents
rsReports.MoveNext
Loop
rsReports.Close

now the eval function will not run the function. the same code works
fine
in AC97. but in AC2007 i get the following error:

Run-time error '2482':

Microsoft Office Access can't find the name 'ClassMerchPrep' you
entered
in the expression.

Hmm. Does rsReports!FuncName have the required parentheses -- () -- on the
end? If it doesn't, I wouldn't expect the Eval function to recognize it.

If that's not the trouble -- and the fact that it works in A97 and not in
A2007 suggests that it isn't -- then it could maybe be the result of Jet
Sandbox Mode:

http://office.microsoft.com/en-us/access/HP010446591033.aspx

You can adjust the operation of sandbox mode or turn it off, if necessary.
The above article should contain a link to a page explaining how to do that.
Are there any alternatives to the eval function?

You might use the Application.Run method:

Application.Run rsReports!FuncName

I don't know whether that is affected by sandbox mode or not.
 
Top