473,785 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
+ 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 20662
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
1879
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" element.onfocus = function() {FocusIsOn = "Button_1"; alert(FocusIsOn)} That works great. If the button gets the focus, I got a message box saying 'Button_1'. However, if I set the variable 'FocusIsOn' dynamically (using a variable
1
6428
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 binding it to a repeater control. This repeater control has multiple text boxes and buttons. Can you please tell me how can i do paging in this case ? I'm posting my code below. The problem is that if i click on "AdjustThisAd" button, it opens...
12
32161
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 frmTest" Thanx
2
60213
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("(" + json + ")"); //ok! var obj2 = eval(json); //syntax error! why are parenthesis necessary?
3
3635
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
1919
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 arrays each select is individually named withe MySelecti where i is an incremental from 1. I know all my variables are correct (i, OptionsCount) and my arrays of MyValues and MyDescription's exist for multiple enteries and if I bring out an...
7
5065
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 Array(); this.values = new Array();
7
1781
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
2677
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 need to specifiy the index key and I can treat it exactly like an array - oSet = ... Are objects just as quick to access/alter as arrays? I have a few
0
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9484
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10157
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10097
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9957
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5386
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.