Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Recorset not refreshed

Posted on 2002-04-24
6
Medium Priority
?
258 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 200 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 101

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses

704 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