473,487 Members | 2,674 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using Eval() function to treat string as VBA statement

5 New Member
Hi guys

I'm trying to use the eval() function to run code that I have previously compiled via string concatenation.

Some of it works, for example, I can set the focus to a combo box called 'AssetIDLookup', which is on the other form, with this code:

Expand|Select|Wrap|Line Numbers
  1. 'First building the string using variables:
  2. buildCommandString = "Forms!" & AppropriateFormName & "!AssetIDLookup.setfocus"
  3. 'Now use eval() and pass the string to have it converted to a VBA statement:
  4. Eval (buildCommandString)
  5.  
So far so good - the focus is successfully set and no errors. However, when I try to use the same method to set the text of that combo box, I keep getting the RunTime error described at the end of my post:

Expand|Select|Wrap|Line Numbers
  1. 'building the string 
  2. buildCommandString = "Forms!" & AppropriateFormName & "!AssetIDLookup.Text = " & AssetID
  3. 'and useing eval() to treat it as a vba statement:
  4. Eval (buildCommandString)
  5.  
Here is the Run Time error (2482):
The application can't find the name 'Asset008' (the actual asset code from my variable) you entered in the expression.

Using msgbox or debug to check the string confirms that the statement is correct. And hardcoding that statement into the procedure also confirms that it works, ie. the combo box is set to eg. 'Asset008'.

Any help/hints would be greatly appreciated :-)

Thanks
Rob
Feb 5 '08 #1
2 20629
rdemarco
5 New Member
Have not found a way to do it with the eval() function, but here is a workaround:

Expand|Select|Wrap|Line Numbers
  1.  Screen.ActiveForm!AssetIDLookup.Text = AssetID
  2.  
It works, but I would still like to hear if anyone has a better idea :-)

Thanks
Rob
Feb 5 '08 #2
SonyBytes
1 New Member
The problem with this one seems to be passing a literal without quotes so your application can't find the literal when it attempts to look for it, instead of assigning it as a text value to your box:
Expand|Select|Wrap|Line Numbers
  1. buildCommandString = "Forms!" & AppropriateFormName & "!AssetIDLookup.Text = " & AssetID
  2.  
Try adding single quotes, since you are building a string, like:
Expand|Select|Wrap|Line Numbers
  1. buildCommandString = "Forms!" & AppropriateFormName & "!AssetIDLookup.Text = '" & AssetID & "'"
  2.  
Aug 28 '08 #3

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

Similar topics

9
1837
by: Stefan Mueller | last post by:
I'd like to set a variable called 'FocusIsOn' if a button got the focus. Because my button is dynamically created I do it like xelement = document.createElement("input") xelement.type = "button"...
1
6388
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
12
32114
by: Maurice | last post by:
Hi, is it possible to enter a string in code in VB.NET 2005 which will be executed as a codeline during runtime? i.e. I want to declare a new form depending on the string: "Dim frm as new...
2
60178
by: radykl | last post by:
Can anyone explain me why you need to add open and close parenthesis to a JSON text in order to use eval() to parse it? For example: var json = "{a: 'abc', b: 'def'}"; var obj1 = eval("(" +...
3
3628
by: ray_usenet | last post by:
Why is this: eval('') is OK, but eval('{"active":"true"}') tells me I'm missing ";" ? Then why is it that if I put parentheses around the second statement:
3
1888
by: Pauljh | last post by:
Hi All, I'm running some javascript over a server side generated web page and have multiple generated empty select statements, that I want to populate when the page is loaded. As HTML doesn't do...
7
5042
by: Darko | last post by:
Hello, I have this particular problem with eval() when using Microsoft Internet Explorer, when trying to define an event handler. This is the code: function BigObject() { this.items = new...
7
1762
by: Ciaran | last post by:
Can someone please give me a hand with this? $arr=array(2,4,5,6); $test='arr'; echo (eval("$".$test."")); I'm trying to get it to echo 2
1
2663
by: bizt | last post by:
Hi, Im currently looking to move into using JSON for AJAX instead of returning from the server a string like the following: 12345{This is a text string{true I prefer objects because I dont...
0
7106
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7181
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7349
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4874
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.