ARW17

Board Regular
Joined
Oct 31, 2016
Messages
109
I'm writing vba to .addnew then .update a table.

Once this is done, I want to clear the fields on the form that was used to update the table.

SOMETIMES the longtext field is cleared before it's written to the table.

If I take out the code that clears the fields, this is fixed.

Why is it that the code isn't completing before the clearing code runs?

I've looked into DoEvents, but can't get this to work.

Help please!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
bound columns update whenever you add, delete or change data. No code required.
 
Upvote 0
Why is it that the code isn't completing before the clearing code runs?
When you use Access, it's common to pass program execution to different services. Memory's a bit fuzzy on the exact details, but there's Jet and the Expression service to name a couple. Code execution can invoke a process on one side while execution continues in the other. Rather than attempt to slow execution down (which is easy enough) you should probably alter the user interaction, such as
- require a command button click to do what you're attempting to delay, assuming a second or two is all that's needed
- alter the form so as to move to a new record (which would automatically clear the controls)
- any other similar delaying tactic

Forgive me if I repeat something already mentioned (I gleaned over all the responses) but please use code tags for more than just a few lines, and proper indentation to make code easier to read. On the code side, because of the way you declared these all on the same line, all of the following are Variant data types
Dim MsgSave, StyleSave, TitleSave, ResponseSave
Don't know if you're aware of that - looks odd because most people explicitly define variable types rather than default to Variant, which is one of the largest uses of computer memory. Most of the time, all declarations are done in the same block near the top.

I guess the rest of the code that you haven't shown takes care of closing and destroying of the rs object (also good practice). Not sure if you understand the difference between "" and Null. Many would test a control for Null when they've set it to "" somewhere else. That test should report False.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,217
Members
448,554
Latest member
Gleisner2

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