Solved

Recorset not refreshed

Posted on 2002-04-24
6
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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.
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…
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…

751 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