VB 4.0, Access 7, DAO: Recordset.Edit / Update problem

I have a Sheridan DBGrid in VB 4.0, bound to a Recordset resulting
from a Query to an Access 7.0 Database.

The problem: The Database cannot be updated. I use Edit and Update, but before
Update, the Recordset has the new Value, after Update it has the old one again:

    Do
        ' Data1.Recordset.Updatable yields True here!
        Data1.Recordset.Edit
        ' Data1.Recordset.Updatable yields True here!
       
        Data1.Recordset!SortValue = Data1.Recordset!SortValue + 1
        'This works, SortValue is incremented from 1 to 2 here.
        Data1.Recordset.Update
        ' ... but here, it is 1, the old value, again! (if Update isn't executed
        ' here, it is performed by "MoveNext")

        Data1.Recordset.MoveNext
    Loop While (Not Data1.Recordset.EOF)
   
The Loop shall increment a special sorting field of each Record, starting
with the current one. The Recordset was the result of a Query
(Data1.Recordset = Query.OpenRecordset()), and is Dynaset-Type. It is requeried
after this action, but has the old values.

The Query, saved in the Database, looks like:
PARAMETERS [Key] Long;
SELECT Bauteilschicht.*
FROM Bauteiltyp INNER JOIN Bauteilschicht ON Bauteiltyp.BT_ID = Bauteilschicht.BT_ID
WHERE (((Bauteiltyp.BT_ID)=[Key]))
ORDER BY Bauteilschicht.SortValue;

I also tried wrapping a transaction around the complete loop, with no effect.

Can anyone tell me what might be wrong ?

If I wanted to implement the source within the Access-Database: would it be
faster ? How is it done, as a macro or as a module ?

One field of the data table is connected to the key
(auto value) of the "parent" table, 1 : n, with referential
integrity, and all updating provided.
LVL 1
PC-AlexAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dirkmartinCommented:
I don't read this much code for 50 points.  I didn't wade through all your code, but rather just to let you know, there is also an UpdateRecord method also.
0
aktisCommented:
This code will work if you create a relationship between the two tables with Update Cascade.
0
PC-AlexAuthor Commented:
Edited text of question
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

PC-AlexAuthor Commented:
Edited text of question
0
PC-AlexAuthor Commented:
aktis:

One field of the data table is connected to the key
(auto value) of the "parent" table, 1 : n, with referential
integrity, and all updating provided.

Sorry, it doesn't work instead.
0
PC-AlexAuthor Commented:
Adjusted points to 100
0
mjsmith032997Commented:
This is the way I do one:

Dim Qd As QueryDef
Dim Rs As Recordset
Set Qd = dAccounts.QueryDefs("qFindAccountDetails")
Qd.Parameters("MailListID") = mUserMailID&
Set Rs = Qd.OpenRecordset()
Set Data1.Recordset = Rs

The DBGrid has to have the properties set to allow edit and updates (AllowAddNew, AllowAupdate), otherwise I can add new records right on the grid and edit records on the grid or by program control with:

Data1.Recordset.Edit
Data1.Recordset("Credit/Debit") = "C"
Data1.Recordset.Update

I hope this helps
0
PC-AlexAuthor Commented:
mjsmith,

I have the two Allows on True, and use nearly the same code;
it doesn't work instead.

Thank you & sorry.
0
PC-AlexAuthor Commented:
Adjusted points to 150
0
PC-AlexAuthor Commented:
Adjusted points to 200
0
avellapCommented:
Are you using the32bit or 16bit VB?
0
PC-AlexAuthor Commented:
32 Bit.
0
PC-AlexAuthor Commented:
Adjusted points to 275
0
ksleungCommented:
Where do you put the above code?
0
PC-AlexAuthor Commented:
I have a special "insert" event, that is triggered after clicking a button.
0
ksleungCommented:
I want to clarify some more before I can figure out the cause of the problem.  Can you show me the special "insert" event (function?) first?  Also, is the Sheridan Data Grid has to do with your update process?  Tell me your flow of program, too.
0
PC-AlexAuthor Commented:
ksleung,

I'm on holiday in the moment, I try to tell you as good as I know from here.
The source of this one function is mainly listed above. The problem is, I want to give users the ability to enter a Row "in between" a SSDBGrid, and the order shall be maintained. So I have a field (SortValue) to contain this sorting information. After a user inserts a Row, this SortValue of the Rows that follow must be incremented by 1. That leads to the problem mentioned.
I guess there are some "AddNew", "Update" and "Edit" commands fired automatically from the SSDBGrid ... but even if so, theoretically the code above should work, but it doesn't.
So much for today, I'm on duty on April 29th next time.

0
BBCCommented:
I must admit, that I really dont understand what the data-sturcture behind is. But here is my proposal to avoid the problem (its the best method for working when using access :)) ):
Give your rows a primary key, e.g. a counter. Save the sorting-position in a seperate table, where you keep  the primary key and the sorting position. Perhaps the update will work properly on this table. For sorting you could use something like the dlookup() function.
0
PC-AlexAuthor Commented:
Hey BBC,
you did not mean that honestly, did ya? The sorting field is an attribute of the record ... where would you come if you'd always create a new table with all that cross-referencing when you encounter such a problem ? Think of the "theoretical", object - oriented approach ... there must be a "proper" way, I still believe in that.
0
PC-AlexAuthor Commented:
worked on the problem today. Got a new trace: I'm sure now that the cause has to do with the Query, from that the recordset results. As one can see in the definition of the query, the SortValue is used as a sorting criteria, and exactly this field isn't updatable later on. There must be some properties of the recordset or data control or database to be set afterwards, to make the changes in this SortField last even behind the update.
I experimented with the database definition of the SortValue, tried "indexed, double values allowed" and "not indexed", also tried "value must be supplied" and "doesn't have to be supplied", all with no effect.
0
BBCCommented:
Just to verify this: Are there double values allowed ? It is not a primary key or something like that ?
0
PC-AlexAuthor Commented:
BBC,
the data type of this OrderValue is Long Integer, and it isn't a primary key.
0
BBCCommented:
Are you sure there is no other procedure for lets say "beforeUpdateRecord" that cancels your update somewhere else ?
0
PC-AlexAuthor Commented:
BBC,
there it is:

Private Sub BaustoffGrid_BeforeUpdate(Cancel As Integer)
    Data1.Recordset!BT_ID = DataBauteilbez.Recordset!BT_ID
    Data1.Recordset!OrderValue = BaustoffGrid.Row
End Sub

0
BBCCommented:
*** in BaustoffGrid_BeforeUpdate
*** Data1.Recordset!OrderValue = BaustoffGrid.Row

is OrderValue an other field than SortValue (used in loop-code), if not, the little BeforeUpdate-Procedure will overwrite the new value !
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PC-AlexAuthor Commented:
Hey BBC,
perhaps you're right, I solved the problem two weeks ago in another, a little more complicated way, and have no time to roll up the whole thing once again now.
But as you were the one to spend the most time trying to help me I give the points to you with an Average grading, I think thats fair.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.