Limitations of Eval Function???

  • Hi,

    Sorry to bother you guys again, but I can't figure this out nor find my answer online.

    I'm trying to update the value of one of my controls using VBA using the following code:

    myString = "Forms!" & SourceForm & ".fkClientID.Value = " & ID
    Eval (myString)

    Where SourceForm is the name of the form that has the fkClientID control on it (there are several), and ID is the ID of an item in a combo list (that has just been added in code).

    I can't seem to change the value of any controls inside an Eval function.  What am I doing wrong.  I can change other properties of controls, just not the value property!

    Thanks in advance.

    Aaron

  • Why can't you use this syntaxe? : Form_FormName.fkClientID = id

  • Because for other reasons I passed the FormName in as a string.  Maybe I didn't have to do that.  Here's why I did:

    1. There are several forms (each with some of the same controls on them)
    2. I need to work with the forms in DoCmd statements, e.g.

    DoCmd.Close acForm, "MainFormProps"

    For the former I can see that I could have used a Form variable instead, and then used the syntax you suggested.

    For the latter case I can only see that a string is possible, so that SourceForm could be any number of values such as "MainFormProps", "MainFormOpps", "frmActiveProposals" etc., and

    DoCmd.Close acForm, SourceForm

    would always work. 

    Do you know of a way to turn a form variable into a string, such as the .ToString method available in .NET?

    Thanks.

    Aaron

     

     

  • You can always do this :

    Dim MyForm as Access.Form

    set MyForm = Application.Forms("FormName")

    MyForm.FkClient = SomeValue

    ...

  • Genius!

    Thank you!

    Aaron

  • It's late binding but at least it works .

  • why not just

    forms("Formname").FkClient = someValue

    save yourself some lines of code

    martin

  • I tried this one but it failed...

    Also he said that he wanted to do more than one operation on the form... so it's faster to set it to a variable than to go through the key names collection each time.

  • It is always better to pass the correct type to the function.  IT allows more control over what you are doing.  You can always convert values to the datatypes you need in many cases.

     

    function MyFunction(byRef oForm as Form) as boolean

       docmd.clos acForm, oForm.name

       myFinction = true true

    end function

    Kindest Regards,
    David

    ** Obstacles are those frightening things that appear when we take our eyes off the goal. **

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply