Solved

Recorset not refreshed

Posted on 2002-04-24
6
235 Views
Last Modified: 2010-05-02
Hi everybody,

I want to insert 50 records in a table let us take it as table1 let us consider there are 3 columns out of which col1 is a primary . i am getting the max of col1 and adding 1 to the col1 and  inserting it into the table. Now when the loop is run, the first record is inserted after that it is giving error saying that record cannot be inserted because of the primarykey violation can anybody say how to perform this operation.

I think the recordset is not refreshed when I am getting max of col1


Thanks in advance

Regards
Pushparaj
0
Comment
Question by:v_pushparaj
6 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 50 total points
ID: 6966735
can you post some code? are you correctly incrementing the key?

ie: (pseudo code)

newKey = Max(col1)

while rs.eof = false
   rs.movenext
   rs.fields("col1") = newKey + 1
   rs.update
   newKey = newKey + 1
wend
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 6967097
listening
0
 
LVL 3

Expert Comment

by:Bahnass
ID: 6967995
Give us
1-Ur Code
2- ADO Version
3- DBASE TYPE (ACCESS 97 OR OTHER)

to see if it is known bug
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:gron
ID: 6968208
What is the field definition for col1 ?
How are you establishing which one is "max" ?
0
 
LVL 18

Expert Comment

by:mdougan
ID: 6971763
It should work if you have each of these operations in approximately this order:

For i = 1 to 50
' this function either searches through the recordset or
' goes back to the db and runs another query to get the max
  x = GetMaxKey()
  x = x + 1
  rs.Addnew
  rs("PKEY").Value = x
  rs("otherfield").Value = "somevalue"
  rs.Update
Next i
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6992866
Admin notified of User neglect. Force-accepted by
Netminder
CS Moderator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

713 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