Eval problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stephane
    New Member
    • Feb 2007
    • 35

    Eval problem

    str_comand = "Forms![dossier]![" & с_select & "].Value = 123"

    Eval(str_comand ) ' it doesn't works

    You are trying to assign a value within the string. You can't do this.
  • stephane
    New Member
    • Feb 2007
    • 35

    #2
    >>You are trying to assign a value within the string. You can't do this.

    str_comand = "Forms![dossier]![" & с_select & "].Value = ""123"""

    doesn't works too

    Comment

    • stephane
      New Member
      • Feb 2007
      • 35

      #3
      i can make question more simply
      how to set value to field using eval function?

      str_comand = "Forms![dossier]![testtest].Value = ""text"""
      Eval(str_comand )

      not works

      Comment

      • MMcCarthy
        Recognized Expert MVP
        • Aug 2006
        • 14387

        #4
        Try this

        Code:
         
        str_comand = "Forms![dossier]![testtest] =" & "text"
        Eval(str_comand)
        It's possible the Eval() won't work like this but it's worth testing.

        Comment

        • stephane
          New Member
          • Feb 2007
          • 35

          #5
          Originally posted by mmccarthy
          Try this

          Code:
           
          str_comand = "Forms![dossier]![testtest] =" & "text"
          Eval(str_comand)
          It's possible the Eval() won't work like this but it's worth testing.
          it doesn't works too (
          well, there is no errors, its simply no changes in 'testtest' field.


          is anybody know other methods to change field, which name contents at the variable? mayby there is way without eval() using?

          Comment

          • MMcCarthy
            Recognized Expert MVP
            • Aug 2006
            • 14387

            #6
            Originally posted by stephane
            it doesn't works too (
            well, there is no errors, its simply no changes in 'testtest' field.


            is anybody know other methods to change field, which name contents at the variable? mayby there is way without eval() using?
            Forgetting about the Eval what are you trying to do?

            Comment

            • Rabbit
              Recognized Expert MVP
              • Jan 2007
              • 12517

              #7
              It seems like you're trying to set the value for a control that could be a different control every time. And for some reason, you don't know what that control is before hand and no event from that control will activate in response. This is one of the few situations where I can see needing the functionality that you want.

              Code:
              Dim ctl As Control
               
              For Each ctl In Form.Controls
              	 If ctl.Properties("Name") = strName Then
              		  ctl = "123"
              		  Exit For
              	 End If
              Next ctl

              Comment

              • stephane
                New Member
                • Feb 2007
                • 35

                #8
                Originally posted by mmccarthy
                Forgetting about the Eval what are you trying to do?
                i've got a form. simply, it there is two text fields, 'text1' and 'text2' and button
                i've got a global variable field_name
                field_name can be equal
                field_name = "text1" or field_name = "text2"
                it takes from another part of form, and it's so.

                clicking on button, a need to set value of the one of those two fields as "test"

                when it's equal text1 i need set "test" as text1 value
                when it's equal text2 needs to set "test" as text2 value

                it is a simplistically example. at real sutiation number of fields is unknown, so i can't use
                Code:
                if field_name = "text1" then
                Forms![dossier]![text1].Value = "test"
                elseif field_name = "text2" then
                Forms![dossier]![text2].Value = "test"
                end if

                Comment

                • stephane
                  New Member
                  • Feb 2007
                  • 35

                  #9
                  Originally posted by Rabbit
                  It seems like you're trying to set the value for a control that could be a different control every time. And for some reason, you don't know what that control is before hand and no event from that control will activate in response. This is one of the few situations where I can see needing the functionality that you want.

                  Code:
                  Dim ctl As Control
                   
                  For Each ctl In Form.Controls
                  	 If ctl.Properties("Name") = strName Then
                  		  ctl = "123"
                  		  Exit For
                  	 End If
                  Next ctl
                  Thanks, Rabbit,
                  i'll try it tomorrow

                  Comment

                  • Rabbit
                    Recognized Expert MVP
                    • Jan 2007
                    • 12517

                    #10
                    There could be a simpler solution. In addition to wanting to know what you want to do with the code is why you need to do it this way. You've told us what you want to do, can you tell us why?

                    Comment

                    • stephane
                      New Member
                      • Feb 2007
                      • 35

                      #11
                      Originally posted by Rabbit
                      There could be a simpler solution. In addition to wanting to know what you want to do with the code is why you need to do it this way. You've told us what you want to do, can you tell us why?
                      at the real situation i've got a form width a lot of "datetime" fields.
                      to make interface more friendly i use object Calendar Control 11.0.
                      but i don't what to make a lot of copies of the calendar object. So i make one calendar, hide it, and when user clicks one of the datetimefields, i change the coordinates of the calendar, show it and set varible for current datetime field. When user selects date, calendar hides, and value of the current datetime field sets equal calendar value selected.

                      so, when the calendar hides, i know name of the current field and sets its value.

                      sorry for bad english:]

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32633

                        #12
                        It sounds like you want the Me.Controls(Con trolName) syntax.
                        The name of the control (ControlName) can be stored in a string variable or can be any formula that returns a string.
                        Let us know if this solves your problem.

                        Comment

                        Working...