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.
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.
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.