Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

kjv1611 (TechnicalUser) (OP)
3 Jul 08 9:46
There may not be an answer to this, but I was wondering...

Is there a way to "fix" Access or at least my current project/database so that when the VBA code is running, the user form doesn't freeze up.  I mean, I don't mind it not being accessible, but I'd like at least for some updates to show on the form.

Currently, on the form of the moment, when I run it, I click a button that starts off a VBA procedure from a Module (not Form Module) - the Form Module just has a call to the procedure.

After the procedure starts, everything pretty much freezes.  During that time, I was wanting to update a couple text fields on the form just mainly to let the user know that the database is still running.  Well, sometimes those fields change, and sometimes they don't, but the procedure always completes.

Does anyone know of a general fix either in code or an option to check on the form to get around this?

Thanks in advance for any thoughts or advice.
 

--

"If to err is human, then I must be some kind of human!" -Me

Helpful Member!  PWise (Programmer)
3 Jul 08 10:08
look @ repaint
kjv1611 (TechnicalUser) (OP)
3 Jul 08 10:19
Thanks, I'll give that a shot.

--

"If to err is human, then I must be some kind of human!" -Me

Helpful Member!  Golom (Programmer)
3 Jul 08 10:21
You could use a class rather than a module

CODE

Option Compare Database
Public Event TheEvent()

Public Sub DoStuff()
    Do Until YouAreDone
        n = n + 1
        If n Mod 100 = 0 Then RaiseEvent TheEvent
        ' Current Module Code.
    Loop
End Sub
And in your form

CODE

Dim WithEvents mc As Class1

Private Sub mc_TheEvent()
    ' Update some field on the form.
End Sub

Private Sub cmdButton_Click()
    Set mc = New Class1
    mc.DoStuff
    Set mc = Nothing
End Sub
kjv1611 (TechnicalUser) (OP)
3 Jul 08 10:27
Yeah, that looks like a nifty way as well.  So using a Class module will somehow free-up the form from just being in sort of a frozen state?

Thanks a bunch for the example, there.

--

"If to err is human, then I must be some kind of human!" -Me

kjv1611 (TechnicalUser) (OP)
3 Jul 08 10:34
For now, I think I will stick with the Repaint method, and then try moving the deal to a Class module later, as this part is not as important as what the procedure is actually doing for now.  It mainly was just a want to - not to mention, that it would be helpful for future users of the database.

Anyway, one thing I did notice though.  The text boxes repopulated like I was wanting (and showed up).

But I was using a few images by just setting the visible option from false to true, true to false to sort of provide a progress bar. Actually it's rather a silly progress bar.

Anyway, that doesn't work while the procedure is running.  Currently, I have that little bit of code in the Form's TimerEvent.

If I used a class module instead of a module, would that fix the timer interval deal, or is that just not possible when running the code from a module?

--

"If to err is human, then I must be some kind of human!" -Me

Golom (Programmer)
3 Jul 08 10:37
Raising an event (as I have coded it) runs code in the form while your long-running code is being processed.

You can also stick a DoEvents in your module to allow other events (like button clicks on the form) to be processed. That can cause problems though.

First of all, it can starve your module ... meaning that code being run by DoEvents will cause processing in the module to be interrupted and therefore take longer.

Second, there may be things that you don't want to allow while your module code is running (for example, clicking the same button and starting the module again.)

Using the class and events lets you show some activity on the form but doesn't allow the user to interfere with what's happening.
kjv1611 (TechnicalUser) (OP)
3 Jul 08 10:40

Quote:


Using the class and events lets you show some activity on the form but doesn't allow the user to interfere with what's happening.

Thanks!  That clears it up quite a bit.  That is EXACTLY what I want to do.  I definitely don't want the user to be able to run another process while this one is running!  Although that could be something to keep in mind for other projects in the future.  I imagine there could be a time when that would be a good thing - just not very often.

--

"If to err is human, then I must be some kind of human!" -Me

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close