I need help using the Eval() function

H

Helpme_Rhonda

General Description:
I am adding many new records from one recordset, to another.
I know this begins with the AddNew method and then the fields are explicitly
declared i.e. (Recordset!Field1 = Value). I don't want to explicitly write
out all of the fields so i want to do this with a loop. It seems like it
should simple but its F***ing frustrating. I already know that my recordsets
have the same number of fields.
Here's what I got:

' This Function strips values from one recordset and places those values 'as
a new row
'in the recordset_to object

Function Row_Insert(rcd_set_to As Recordset, rcd_set_from As Recordset)

Dim intCounter As Long

intNumberFields = rcd_set_from.Fields.Count
rcd_set_to.AddNew

For intCounter = 0 To intNumberFields - 1
temp = Get_Field_Name(intCounter, rcd_set_to)
Eval (temp)
Next intCounter
rcd_set_to.Update

End Function

' This function returns the Fieldnames for the index value given

Function Get_Field_Name(indx As Long, rcd_set As Recordset) As String

Get_Field_Name = "rcd_set_to!" & rcd_set.Fields(indx).Name & " =
rcd_set_from.Fields(intCounter).Value"

End Function

Here is the error:
Run-time errror '2482':
MS Office Access cant find the name 'rcd_set_to' you entered in the
expression becuase it's moodier than your emo girlfriend/boyfriend.

So the string function to evaluate is
rcd_set_to!Field_name = rcd_set_from.Fields(intCounter).Value
which works if I break at runtime then debug.print the string and continue
with the string in.
 
M

Marshall Barton

Helpme_Rhonda said:
General Description:
I am adding many new records from one recordset, to another.
I know this begins with the AddNew method and then the fields are explicitly
declared i.e. (Recordset!Field1 = Value). I don't want to explicitly write
out all of the fields so i want to do this with a loop. It seems like it
should simple but its F***ing frustrating. I already know that my recordsets
have the same number of fields.
Here's what I got:

' This Function strips values from one recordset and places those values 'as
a new row
'in the recordset_to object

Function Row_Insert(rcd_set_to As Recordset, rcd_set_from As Recordset)

Dim intCounter As Long

intNumberFields = rcd_set_from.Fields.Count
rcd_set_to.AddNew

For intCounter = 0 To intNumberFields - 1
temp = Get_Field_Name(intCounter, rcd_set_to)
Eval (temp)
Next intCounter
rcd_set_to.Update

End Function

' This function returns the Fieldnames for the index value given

Function Get_Field_Name(indx As Long, rcd_set As Recordset) As String

Get_Field_Name = "rcd_set_to!" & rcd_set.Fields(indx).Name & " =
rcd_set_from.Fields(intCounter).Value"

End Function

Here is the error:
Run-time errror '2482':
MS Office Access cant find the name 'rcd_set_to' you entered in the
expression becuase it's moodier than your emo girlfriend/boyfriend.

So the string function to evaluate is
rcd_set_to!Field_name = rcd_set_from.Fields(intCounter).Value
which works if I break at runtime then debug.print the string and continue
with the string in.


Eval will evaluate an **expression** in its argument string,
but it can not execute an assignment **statement**

You should be able to get what you need without messing
around with Eval:

For intCounter = 0 To intNumberFields - 1
rcd_set_to(rcd_set_from.Fields(intCounter).Name) _
= rcd_set_from.Fields(intCounter).Value
Next intCounter
 
H

Helpme_Rhonda

"Marshall Barton"

MVP All-Star...All-World!!
I hope they pay you lots of money...cause your good!!!
You're my new best friend.
 
M

Marshall Barton

Helpme_Rhonda said:
"Marshall Barton"

MVP All-Star...All-World!!
I hope they pay you lots of money...cause your good!!!
You're my new best friend.


Thanks for the kind words, but we're just unpaid volunteers.
The reward comes from helping where we can.
 
V

vanderghast

....and learning. It is like weight lifting: more you do, better you became.
If you are only to deal with your 'own life' problem, you do less 'exercice'
than if you also manage, somehow, to deal with many other problems that your
real life would have probably never brought to you! So helping, or even
reading about other kind of problem can make everyone better, a reward in
itself too.

Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top