Can procedures run simultaneously?

M

Milan

Hello,

I have got the following problem. When some user clicks on the
command-button placed on my form the time-consuming operation starts
to run. That is why I want to display some information text in some
caption or text box which would change by every let's say second. I
have written this timer procedure:

Sub Info()
Me.Text1.Caption = " . . .Proceeding . . ."
Me.Text2.Caption = ". . . Proceeding. . . "
End Sub

Sub Form_Timer()
Me.Text1.Visible = Not Me.Text1.Visible
Me.Text2.Visible = Not Me.Text1.Visible
End Sub

I don´t want to use status bar. The problem is that the timer event
procedure and the button_click procedure don´t run simultaneously. I
tried to use 2 forms but the result was the same.

Can someone tell me what to do?

Thanks,
Milan
 
S

Sandra Daigle

Hi Milan,

AFAIK there is no real way to have simultaneous procedures. However you can
design your procedure in such a way that you can display status messages to
the screen.

First off, it really depends on what you are doing that takes a long time to
run. If it is a long running query then I don't think theres much you can do
because Access won't yield any CPU time to allow you to get messages
written or displayed to the screen. If you have multiple queries or steps
then the key to updating the screen is to use the "DoEvents" command to tell
Access/VBA to yield a little CPU time to handle lower priority tasks such as
updating the display.

You would need to embed this in the code that is taking up the CPU time (ie
your command button click event). Let's say that your click event contains
some sort of loop:

for i = 1 to 100000
'
'do your real stuff
'
Me.Text1.Caption = " . . .Proceeding . . ."
Me.Text1.Visible = Not Me.Text1.Visible
doevents
next i

This is going to flash very quickly and it is also taking CPU time away from
the real processing so I would recommend putting in a second counter to only
flash the status on every Nth iteration:

Dim i As Integer
Dim j As Integer
For i = 1 To 10000
'
'do your real stuff
'
'second counter
j = j + 1
If j = 30 Then
Me.Text1.Caption = " . . .Proceeding . . ."
Me.Text1.Visible = Not Me.Text1.Visible
DoEvents
j = 0
End If
Next i


Another way of doing this uses the Mod statement (look at help on this):

Private Sub Command13_Click()
Dim i As Integer
Dim j As Integer
For i = 1 To 10000
'
'do your real stuff
'
If i Mod 30 = 0 Then
Me.Text1.Caption = " . . .Proceeding . . ."
Me.Text1.Visible = Not Me.Text1.Visible
DoEvents
End If
Next i

End Sub


Now, having said all this you can look at my website
http://www.daiglenet.com/MSAccess.htm and check out the progress meter
examples.
 
A

Albert D. Kallal

Sandra's comments can't be beat. That is real classic computer stuff "mod"
and loops! (brings me back to my old apple II days!).

I do however have a nice progress bar that DOES run independently of your
code..and can update all by its self.

Try downloading my super easy word merge. You can try sing the word merge to
see how the progress bar works, and there is also a sample on the form to
test the progress bar. You will find that word merge with the sample
progress bar here:

http://www.attcanada.net/~kallal.msn/msaccess/msaccess.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top