Solved

Recorset not refreshed

Posted on 2002-04-24
6
216 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 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