Can't get auto-close function to work without affecting other functions?

barbd777

New Member
Joined
Mar 29, 2016
Messages
9
Hoping someone here can help me? I started this post on Excel Forum: Adding auto-close code to existing?
I got some suggestions there, but either the auto-close codes proposed were affecting the auto-save and clear contents, OR I was getting compile errors (and I don't know enough about code to fix them on my own!). My last answer there was almost a month ago, so Yes, I am cross-posting! I have a fully-functioning form that is SO close to being ready to release for use; I just need to have an auto-close function that works without affecting or blocking the other functions! I have code for the Submit button posted there, the last one being what I tried and thought worked, only to find that my userforms fields weren't clearing. The entire .xls workbook has also been posted there, if anyone would like to take a look. I'm sure this is something ridiculously simple for someone who knows coding...would really appreciate any suggestions. Thanks!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
What exactly do you mean by an 'auto-close' function?

How/when would such a function be executed/triggered?
 
Upvote 0
Hi Norie--I have a userform that populates to a database worksheet; after the form is filled out, the user hits the Submit button, which populates the database, opens a Save as PDF dialog, attaches the PDF to an email, then Clears Contents in the userform. Previously, I had auto-save code running in a separate ThisWorkbook module. In testing, we realized we need an auto-close function, so that the form closes out after use and is available for the next user. SO that is what I'm trying to add to the Submit button. If you look at the cross-post, you can see that my last attempt was to add
Code:
<code>ActiveWorkbook.Save
ActiveWorkbook.Close</code>
after the ClearContents code. I thought this worked, since it did auto-save AND auto-close the form, but when I re-opened, the contents of the userform fields did not clear. That's my dilemma!
 
Upvote 0
In the thread on the other forum there was no userform in the workbook you uploaded, that's kind of why I didn't post anything else to the thread.

As I said in the other thread the simple way to close a userform is to use this.
Code:
Unload Me
Now if that's interfering with other events in the userform code can be added to deal with that.
 
Upvote 0
Hi Norie--the first page of that workbook is the userform I'm referring to (no VBA (?) form). This was something I dowloaded from contextures.com and adjusted for our uses.
Can you take another look at it in regards to the code I'm referring to? I got compile errors attempting to use Unload Me...
Thanks!!!
 
Upvote 0
I've tried about 6 different code solutions in ThisWorkbook module to save and close, either on submittal of the data entry form, or after a period of inactivity if the user leaves the workbook open. ALL are causing problems, primarily interfering with the Clear Contents function of the data entry form; some also bring up a Save dialog, which I don't want, and wasn't happening before. I haven't been getting ANY responses lately...does anyone have ANY ideas that might accomplish waht I need??? I would really appreciate some help--thanks!
 
Upvote 0

Forum statistics

Threads
1,215,143
Messages
6,123,275
Members
449,093
Latest member
Vincent Khandagale

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