Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Key column information is insufficient or incorrect

Status
Not open for further replies.

Glasgow

IS-IT--Management
Jul 30, 2001
1,669
0
0
GB
Hi

I am testing an old VB6 application under Windows 7 and code that has been working fine for years is now failing. The code below updates order detail lines that have been entered via a grid. The grid can include old rows and newly added rows. The order detail table has a primary key (auto-increment ID) and a foreign key that links to the order header which is set in the loop.

Code:
   If Not Fm.RsTdg Is Nothing And Fm.FrgnFldTo <> "" Then
     With Fm.RsTdg
       If Not (.EOF And .BOF) Then     'Need to cycle through the subgrid records
         .MoveFirst                    'and assign any id field that links them
         Do Until .EOF                 'with the main parent record. This can
           .Fields(Fm.FrgnFldTo) = Fm.Table(Fm.FrgnFldFrom) 'only be done here
           .MoveNext                   '(after main parent has been saved) as
         Loop                          'only now will that parent ID be assigned
       End If
       .UpdateBatch
     End With
   End If

The error occurs on the UpdateBatch and only when some of the rows in the table are new and have been added to the grid but not yet saved to the database (hence no primary key ID yet assigned I suppose). It suggests a kind of chicken and egg problem. Note that the records are actually still added to the database OK!

The most significant difference in the environment is that I have recently upgraded to SQL 2008 R2. The error occurs under both XP and Windows 7.

Any help would be greatly appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top