By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,426 Members | 3,118 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,426 IT Pros & Developers. It's quick & easy.

Eval problem

stephane
P: 35
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.
Feb 8 '07 #1
Share this Question
Share on Google+
11 Replies


stephane
P: 35
>>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
Feb 8 '07 #2

stephane
P: 35
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
Feb 8 '07 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
Try this

Expand|Select|Wrap|Line Numbers
  1.  
  2. str_comand = "Forms![dossier]![testtest] =" & "text"
  3. Eval(str_comand)
It's possible the Eval() won't work like this but it's worth testing.
Feb 8 '07 #4

stephane
P: 35
Try this

Expand|Select|Wrap|Line Numbers
  1.  
  2. str_comand = "Forms![dossier]![testtest] =" & "text"
  3. 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?
Feb 8 '07 #5

MMcCarthy
Expert Mod 10K+
P: 14,534
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?
Feb 8 '07 #6

Rabbit
Expert Mod 10K+
P: 12,366
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.

Expand|Select|Wrap|Line Numbers
  1. Dim ctl As Control
  2.  
  3. For Each ctl In Form.Controls
  4.      If ctl.Properties("Name") = strName Then
  5.           ctl = "123"
  6.           Exit For
  7.      End If
  8. Next ctl
  9.  
Feb 8 '07 #7

stephane
P: 35
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
Expand|Select|Wrap|Line Numbers
  1. if field_name = "text1" then
  2. Forms![dossier]![text1].Value = "test"
  3. elseif field_name = "text2" then
  4. Forms![dossier]![text2].Value = "test"
  5. end if
  6.  
Feb 8 '07 #8

stephane
P: 35
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.

Expand|Select|Wrap|Line Numbers
  1. Dim ctl As Control
  2.  
  3. For Each ctl In Form.Controls
  4.      If ctl.Properties("Name") = strName Then
  5.           ctl = "123"
  6.           Exit For
  7.      End If
  8. Next ctl
  9.  
Thanks, Rabbit,
i'll try it tomorrow
Feb 8 '07 #9

Rabbit
Expert Mod 10K+
P: 12,366
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?
Feb 8 '07 #10

stephane
P: 35
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:]
Feb 8 '07 #11

NeoPa
Expert Mod 15k+
P: 31,494
It sounds like you want the Me.Controls(ControlName) 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.
Feb 10 '07 #12

Post your reply

Sign in to post your reply or Sign up for a free account.