using Eval()

smig

Registered User.
Local time
Today, 07:45
Joined
Nov 25, 2009
Messages
2,209
I'm trying to run this piece of code, but I get an error
Code:
Public Function fnNoWorkDays()
  Dim strOpenArgs As String
  strOpenArgs = "DoCmd.OpenForm 'NoWorkDays_Form', acNormal, , , , acDialog"
  DoCmd.OpenForm "MonthSchedule", , , , , acDialog, strOpenArgs
End Function
 
and in the MonthSchedule's button click
 
Sub MyBtn_Click()
  Eval (Me.OpenArgs)
end sub
 
Could you do this instead?
Code:
Public Function fnNoWorkDays()
  DoCmd.OpenForm "MonthSchedule", , , , , acDialog, "NoWorkDays_Form"
End Function
 
Sub MyBtn_Click()
  DoCmd.OpenForm Me.OpenArgs, acNormal, , , , acDialog
end sub
IMO, it's not really a place where you need Eval().
Mark
 
It's either smig is trying to pass different commands via open args or he's using the same command but needing to pass different forms. If the latter is the case, why don't you just pass the form name?

I agree with lagbolt, it's not the kind of thing you use Eval() for.
 
At first I did pass the form name (And it worked as expeced) but later I had a thought in mind to make it more flexieble :D
 
I can see that you are experimenting smig :D

Eval() returns a String or a Number type and it's expecting a function name or a reference to a control or fiel, whereas in your case DoCmd.OpenForm does not meet the criteria. It will break at DoCmd.
 
Thanks :)
So I'll stick to sending the form name at the moment.
If I'll ever have any need to send anything else I will create another function that will include the Docmd. in it, and will be run using the eval.
 
Last edited:
That will be the wise thing to do. :)
If you're going to write DoCmd then there really is no need trying to Eval() the other parts like lagbolt pointed out.
 

Users who are viewing this thread

Back
Top Bottom