Solved Error 2482 with Eval() - I guess I do not understand Eval limitations (1 Viewer)

Sonnydl

Registered User.
Local time
Today, 05:32
Joined
Jul 3, 2018
Messages
41
Hello,

I've got a workaround for my problem, but I'm trying to learn about what it is that I'm missing. Here's what I ended up with, and it works just fine:

Code:
Private Sub CheckAndProceed(bytRequest As Byte)

...Stuff happens to get the the select statement...

Select Case bytPreCheck
    Case 1
        strMessage = "You are about to request payment:"
    Case 2
        strMessage = "You are about to request PRE-PAYMENT:"
    Case 11
        strMessage = "You are about to update:"
    Case 12
        strMessage = "You are about to update for PRE-PAYMENT:"
End Select

strMessage = strMessage & vbCrLf & vbCrLf & "  " & Chr(149) & intCount & " Payment Detail Record(s)." _
& vbCrLf & "  " & Chr(149) & "Totaling " & strCurrency & " " & Format(sngSum, "Standard") _
& vbCrLf & vbCrLf & "Would you like to proceed?"

If MsgBox(strMessage, vbYesNo, "UPDATE RECORDS?") = vbYes Then
    Select Case bytPreCheck
        Case 1
            RequestReimbEmail Me.txtSubjectID, False
        Case 2
            RequestReimbEmail Me.txtSubjectID, True
        Case 11
            MarkReadyToProcess intCount, Me.txtSubjectID, False
        Case 12
            MarkReadyToProcess intCount, Me.txtSubjectID, True
    End Select
End If

End sub

What I'd hoped to do was:
Code:
Private Sub CheckAndProceed(bytRequest As Byte)

...Same stuff happening...

Select Case bytPreCheck
    Case 1
        strMessage = "You are about to request payment:"
        strFunction = "RequestReimbEmail Me.txtSubjectID, False"
    Case 2
        strMessage = "You are about to request PRE-PAYMENT:"
        strFunction = "RequestReimbEmail Me.txtSubjectID, True"
    Case 11
        strMessage = "You are about to update:"
        strFunction = "MarkReadyToProcess intCount, Me.txtSubjectID, False"
    Case 12
        strMessage = "You are about to update for PRE-PAYMENT:"
        strFunction = "MarkReadyToProcess intCount, Me.txtSubjectID, True"
End Select

strMessage = strMessage & vbCrLf & vbCrLf & "  " & Chr(149) & intCount & " Payment Detail Record(s)." _
& vbCrLf & "  " & Chr(149) & "Totaling " & strCurrency & " " & Format(sngSum, "Standard") _
& vbCrLf & vbCrLf & "Would you like to proceed?"

If MsgBox(strMessage, vbYesNo, "UPDATE RECORDS?") = vbYes Then Eval (strFunction)

End Sub

But when I do it this way, I get "Run-time error '2482': [ProgramName] cannot find the name 'RequestReimbEmail' you entered in the expression."

If you have the time, I'd love to learn why the latter code won't execute as I'd expected. Thanks.
 

Isaac

Lifelong Learner
Local time
Today, 05:32
Joined
Mar 14, 2017
Messages
8,738
But you didn't post the code for RequestReimbEmail? How could anyone answer this without it?
 

Micron

AWF VIP
Local time
Today, 08:32
Joined
Oct 20, 2018
Messages
3,476
If you pass a function name to Eval, you must include () after the function name. Maybe

"MarkReadyToProcess() intCount, Me.txtSubjectID, False"
 

Sonnydl

Registered User.
Local time
Today, 05:32
Joined
Jul 3, 2018
Messages
41
But you didn't post the code for RequestReimbEmail? How could anyone answer this without it?

Sorry, I get the same "cannot find" for the MarkReadyToProcess options. My assumption was that the issue is with how I'm using Eval, not the actual subs that are being called, as they work if I don't use the Eval() method. If the issue was the actual subs, wouldn't they fail when called directly?

It also occurred to me that the subs are on a Report, not a form.

Code:
Private Sub RequestReimbEmail(lngSubjectID As Long, blnFuture As Boolean)
...creates and sends an email in Outlook...
End Sub

Private Sub MarkReadyToProcess(intTravelItemCount As Integer, lngSubjectID As Long, blnFuture As Boolean)
...just edits the records...
End Sub

Again, for of these execute when not trying to use the Eval method.
 

June7

AWF VIP
Local time
Today, 04:32
Joined
Mar 9, 2014
Messages
5,425
Consider:

strFunction = "MarkReadyToProcess(" & intCount & ", " & Me.txtSubjectID & ",True}"

Must be a Function not a Sub procedure.
 
Last edited:

Sonnydl

Registered User.
Local time
Today, 05:32
Joined
Jul 3, 2018
Messages
41
Consider:

strFunction = "MarkReadyToProcess(" & intCount & ", " & Me.txtSubjectID & ",True}"

Must be a Function not a Sub procedure.

Yep. When I tried it without making it a function I got a Run-time error 2425: The expression you entered has a function..." So I changed it to a function and... still no joy. Same 2425 Error.

The call code is:
Code:
    Eval ("RequestReimbEmail(" & Me.txtSubjectID & "," & True & ")")

The function is now:
Code:
Public Function RequestReimbEmail(lngSubjectID As Long, blnFuture As Boolean)
...does the same stuff...
End Function
 

June7

AWF VIP
Local time
Today, 04:32
Joined
Mar 9, 2014
Messages
5,425
Works for me but my Function is in general module.

If you want to provide db for analysis, follow instructions at bottom of my post.
 

Sonnydl

Registered User.
Local time
Today, 05:32
Joined
Jul 3, 2018
Messages
41
Works for me but my Function is in general module.

If you want to provide db for analysis, follow instructions at bottom of my post.

Thank you for your help. I got it to work by doing the following:
  1. I moved the subroutines into their own module (out of the report's processes) and converted them into functions.
  2. I removed the function variables from the all-inclusive string and put them in the suggested concatenated form.
  3. I do not need to run the function on the right side of an equation.
So I guess the answers for me are that Eval() needs to call a function and not to put functions in a report process. I cannot say that other than Eval() needing a function that I have the definitive answer on why it didn't work when that function was in the report's modules rather than as a stand-alone module.
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:32
Joined
Feb 28, 2001
Messages
27,001
Sonnydl said:
I'd love to learn why the latter code won't execute as I'd expected.

Eval evaluates an expression that returns a value. It can evaluate a function if it can see the function. Your Post #8, step 1, made the function visible (put it in Public scope) so that Eval could find it using the "standard" expression evaluator. What Eval does, in brief, is takes the right-hand side of an assignment statement and evaluates it. But the acid test of whether it would work or not is whether the following works:

Code:
Dim A as Variant
...
    A = {expression to be evaluated)

If the above works, then an Eval call for that expression that follows the "=" should also work providing you get any required quotes properly managed. However, Eval is concerned about where it is executing, and it is NOT where you might have thought. That is why you had to move things around to be visible.
 

Micron

AWF VIP
Local time
Today, 08:32
Joined
Oct 20, 2018
Messages
3,476
and put them in the suggested concatenated form.
visibility of the function aside, what does that mean? Does it mean you incorporated the parentheses (and I suppose the parameters) as mentioned in my post and at ms access site:

Note: If you are passing the name of a function to the Eval function, you must include parentheses after the name of the function in the stringexpr argument. For example:
' ShowNames is user-defined function.
Debug.Print Eval("ShowNames()")

Debug.Print Eval("StrComp(""Joe"",""joe"", 1)")
or something else?
Thanks.
 

Users who are viewing this thread

Top Bottom