"Transactional" record updates

Montez659

Well-known Member
Joined
May 4, 2005
Messages
918
Can anyone point me in the direction of a "transactional" record update?

What I mean is that I have 4 different SQL statements in vba executing on a command button, and if any one of those fail, I want the whole thing to fail. Otherwise, junk records will be created.

I would google it but I really don't even know the correct terminology to search for.

Thanks in advance.
 
Okay. Simplest is if you have a form. When you begin a new record the autonumber value is assigned (populated) right then. So I think you can take it right from the form field. Is that possible?

I can think of at least three other ways to do this (and I'm sure I could come up with three more). But of course, simplest is best in most cases.
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
That's how a typical bound form would work wouldn't it? But I am trying to avoid the creation or saving of the record until all information is filled out.

Ok, come to find out, I am not sure that it is the fact that the record isn't being committed that is the problem. I moved the Dlookup outside of the transaction and it is still retrieving the previous records id. I am wondering if there is a lag between the committing process and the actual populating of that record to the table.

I definitely need something more consistent. So, are you suggesting that the form be bound to the autonumber field only and create the id as soon as data is entered? If this is the case how would you go about canceling the record if you don't want it - a delete query?
 
Upvote 0
Montez

You can cancel a record by hitting Esc.

Then it won't get saved to the table.

The only thing is, and it shouldn't really matter, the autonumbering will skip one.

eg if you start a new record and it's auto number is 20 but you cancel it the next record will have the auton number 22, not 21

Of course if you are using a random autonumber...
 
Upvote 0
I think it's default, not only on most forms but tables too.

Of course if you have code that's saving the record rather than Access saving it like it usually does things might be different.
 
Upvote 0
^^ Right. ESC once cancels the current control if you are in a textbox or combobox (or what have you). ESC twice and you cancel the entire form. Nothing is committed. Same as Me.Cancel when in form code.

A lot depends on if you are working with a form or purely in code. Of course, you might answer "both" - but if you have a form to hold your code (even a hidden one) it can be bound to the table with your autonumber field in the form. In that case, it would be populated by Access as soon as you start a new record.

-----

About "lags" - the main thing is that in most databases (Access included) data that is uncommitted may not be visible outside of its transaction.
 
Upvote 0
Montez

Are you not including the autonumber field in your forms?
 
Upvote 0
About "lags" - the main thing is that in most databases (Access included) data that is uncommitted may not be visible outside of its transaction
Yeah, but I had actually comitted the transaction and it seems that there was still a lag after that. When I stepped through the code, it seemed to pick it up. Who knows, not the best way to do it anyways.

Are you not including the autonumber field in your forms?
No, I was doing it all via CurrentDB.Execute in VBA so there was no need to include it.

Same as Me.Cancel when in form code.
So technically, if I made all the controls of the form bound and then had a "Cancel" command button with Me.Cancel in it, the record would never be (technically) be created (although the next autonumber would be skipped)?
 
Upvote 0
Sorry I don't understand.

What were/are you using CurrentDB.Execute for?

To update/append to the junction table?
 
Upvote 0
I had three different tables that were being updated. Two were having new records added to them, one of those was a Junction table. The third was an update query, which will still need to be run.

The reason I did this all in code was to keep the record from saving until after all of then information was correctly input.
 
Upvote 0

Forum statistics

Threads
1,225,149
Messages
6,183,178
Members
453,151
Latest member
Lizamaison

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top