Solved

string problem

Posted on 2001-06-22
6
126 Views
Last Modified: 2010-05-02
When I want to populate a recordset with values from another like
-----------
do while not rset1.eof()
   rset2.addnew
       rset2!name=rset1!name
   rset2.updatebatch
loop
------------
Curiosly in one computer it works fine in another one it gives an error and I must change to the following code
------------
dim var as string
 VAR=rset1!name
do while not rset1.eof()
   rset2.addnew
       rset2!name=VAR
   rset2.updatebatch
loop
----------
Must I convert the record to a string?

Thanks
0
Comment
Question by:asimoes
  • 3
  • 2
6 Comments
 
LVL 10

Expert Comment

by:caraf_g
ID: 6217533
only thing I can think of is that you're using different ways of connecting to your data. E.g. ODBC on one machine and OLEDB on t'other...... !?
0
 
LVL 18

Expert Comment

by:deighton
ID: 6217623
The two pieces of code have different functionality, Var is being set outside the rset1 loop in the second example  and will then not change, in the second example rset1!name changes as you move through rset1

(I presume you are navigating through the rset1 recordset somehow, codes you posted is infinite loop isn't it?)  

Post the actual code if possible

Could rset1!name be null and rset2 does not allow a null?
 
0
 
LVL 9

Accepted Solution

by:
Valliappan AN earned 100 total points
ID: 6217845
Try like this:

do while not rset1.eof()
  rset2.addnew
  rset2!name=rset1("name").Value   'NOTE THE CHANGE in accessing property of recordset here.
  rset2.updatebatch
  rset1.movenext  'or whatever code....
loop

A better alternative, is to use direct SQL statements to do this like(if it suits to you), like this:

Conn.Execute "INSERT INTO table2(name) SELECT name FROM table1"

This is a faster one, I dont know, this suits you or not.

Hope this helps, Cheers.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 10

Expert Comment

by:caraf_g
ID: 6218183
Hm...... I wonder though *why* it works..... !?

To be completely unambiguous, perhaps:

rset2.Fields("name").Value = rset1.Fields("name").Value
0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6218880
caraf_g,
I also do so. But I think it is setting as a reference,  when assigning a recordset field to another recordset field, it gives error. But not to variables, I suppose.

So, when assigning a recordset field to another recordset field, needs to assign its value.

asimoes,
Thanks.

Cheers.
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 6218969
Yeah..... maybe.... Hm.... Anyway. Interesting :o)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now