473,320 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

yet another eval() questiion



ok - trying to use eval() to abstract out an update operation i need to
perform. I wanted to use the eval() function to avoid HARD CODING
the field names that need to be updated in the target table. As long as the
SQL fields names matched the field names in the target table I expected this
to work. But the eval() function generates an error - it does not
recognize 'asr' as a recordset.

maybe there's in error in my syntax? maybe this is hopeless........and
maybe there is an easier way -- without having to hardcode the target
table's field names..........???

all (any) replies much appreciated. ))
'=========================
SUB mysub(ars as dao.recordset)
'=========================
Dim strSQL As String
Dim rs As dao.Recordset
Dim fld As dao.Field
Dim str As String

On Error GoTo errhdl

strSQL = "SELECT DISTINCT fld1, fld2, fld3, fld4 FROM mytbl WHERE x = y;"
Set rs = CurrentDb.OpenRecordset(strSQL)

If rs.EOF And rs.BOF Then
Err.Raise gclngBlankCustomerData
End If

'loop thru all fields in this rs - they should have the same name as the
target tbl fields (on purpose)
'update each match between ars and rs

For Each fld In rs.Fields
If Not IsNull(fld.Value) Then
str = "ars![" & fld.Name & "] = " & Chr(34) & fld.Value & Chr(34)
Eval (str) <==== error is here !
End If
Next

--
kent eilers
ke**@kaeServices.com
Nov 12 '05 #1
2 2906
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I believe you can do this without using the Eval() function.

Instead of using this:

str = "ars![" & fld.Name & "] = " & Chr(34) & fld.Value & Chr(34)
Eval(str)

use this:

ars(fld.Name) = fld.Value

HTH,

MGFoster:::mgf
Oakland, CA (USA)
-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP7wWkYechKqOuFEgEQLpAgCg8zFR3Db5a/CTtbjcY3kyHvA+RkIAnRp/
xKipxK/+REHRvC73BvTuy1hN
=aEKr
-----END PGP SIGNATURE-----

Kent Eilers wrote:
ok - trying to use eval() to abstract out an update operation i need to
perform. I wanted to use the eval() function to avoid HARD CODING
the field names that need to be updated in the target table. As long as the
SQL fields names matched the field names in the target table I expected this
to work. But the eval() function generates an error - it does not
recognize 'asr' as a recordset.

maybe there's in error in my syntax? maybe this is hopeless........and
maybe there is an easier way -- without having to hardcode the target
table's field names..........???

all (any) replies much appreciated. ))
'=========================
SUB mysub(ars as dao.recordset)
'=========================
Dim strSQL As String
Dim rs As dao.Recordset
Dim fld As dao.Field
Dim str As String

On Error GoTo errhdl

strSQL = "SELECT DISTINCT fld1, fld2, fld3, fld4 FROM mytbl WHERE x = y;"
Set rs = CurrentDb.OpenRecordset(strSQL)

If rs.EOF And rs.BOF Then
Err.Raise gclngBlankCustomerData
End If

'loop thru all fields in this rs - they should have the same name as the
target tbl fields (on purpose)
'update each match between ars and rs

For Each fld In rs.Fields
If Not IsNull(fld.Value) Then
str = "ars![" & fld.Name & "] = " & Chr(34) & fld.Value & Chr(34)
Eval (str) <==== error is here !
End If
Next


Nov 12 '05 #2
"Kent Eilers" <ka*****@uswest.net> wrote in message news:<hP*******************@twister.rdc-kc.rr.com>...
ok - trying to use eval() to abstract out an update operation i need to snippage For Each fld In rs.Fields
If Not IsNull(fld.Value) Then
str = "ars![" & fld.Name & "] = " & Chr(34) & fld.Value & Chr(34)
Eval (str) <==== error is here !
End If
Next


Kent,
how about replacing the "str= "ars..." and Eval(str) lines with:
ars.fields(fld.Name) = fld 'value is the default
I would expect this to work.

Best of luck,
Martin
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Reply Via Newsgroup | last post by:
This might sound sad... someone requesting a disertation on the 'eval' statement... but... I've been reading someone else's post - they had a huge calander like script and a handful of folk cursed...
11
by: sneill | last post by:
I have read a number of posts on the use of eval() in Javascript, and I agree that its use is questionable. But it does beg the following question: "How arbitrary does a string need to be before...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
15
by: manstey | last post by:
Hi, I have a text file called a.txt: # comments I read it using this:
3
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...
4
by: Jm lists | last post by:
Hello members, I want to know does the "eval" in python have the same features as in Perl (capture errors)? For example,in perl I can wrote: $re = eval { 1 / 0 }; Though 1/0 is a fatal...
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
5
by: wendallsan | last post by:
Hi all, I'm running into a situation where it seems that JS stops executing as soon as I call an eval in my script. I have an Ajax.Request call to a PHP page that builds a JS object and returns...
10
by: Gordon | last post by:
I have a script that creates new objects based on the value of a form field. Basically, the code looks like this. eval ('new ' + objType.value + '(val1, val2, val3'); objType is a select with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.