VBA forgets to execute some lines of code !

L

Laban Twissel

Hi! Happy new year!

I'm facing a strange problem!
I use ACCESS 2002 with an ACCESS 2000 mdb file.
I've got a bouton named btn, and here is the code corresponding to the
OnClick event :

Private Sub btn_Click()
Me.btn.Caption = "Process is running" Line1
Me.btn.BackColor = 65535 Line2
Call Procedure1 Line3
Me.btn.Caption = "Process is completed" Line4
Me.btn.BackColor = 16777164 Line5
End Sub

Procedure1 takes a few seconds to execute.

The problem is that the code on line1 and line2 is not executed, unless I
put a stop point on line2 and line3 !! If I only put a stop point on line2,
then the code on line1 executes well but not that code on line2.

I don't know if a kind of "pause" function could be of interest, anyway I
couldn't find one in Visual Basic's help.

Please help me, I'm just about to throw my computer out of the window ! :)

Thanks for it (the computer), and sorry for my approximative english.

Laban.

--
 
T

Todd Shillam

I am not sure why you are getting the error; however, have you tried a For loop--maybe it would help to make sure the first two lines take place. Perhaps the property settings do not get applied until after the procedure takes place. Nonetheless, here's an idea:

Private Sub btn_Click()
Dim i As Integer

For i = 1 to 2

Me.btn.Caption = "Process is running" Line1
Me.btn.BackColor = 65535 Line2

Next %i

Call Procedure1 Line3
Me.btn.Caption = "Process is completed" Line4
Me.btn.BackColor = 16777164 Line5
End Sub

Hi! Happy new year!

I'm facing a strange problem!
I use ACCESS 2002 with an ACCESS 2000 mdb file.
I've got a bouton named btn, and here is the code corresponding to the
OnClick event :

Private Sub btn_Click()
Me.btn.Caption = "Process is running" Line1
Me.btn.BackColor = 65535 Line2
Call Procedure1 Line3
Me.btn.Caption = "Process is completed" Line4
Me.btn.BackColor = 16777164 Line5
End Sub

Procedure1 takes a few seconds to execute.

The problem is that the code on line1 and line2 is not executed, unless I
put a stop point on line2 and line3 !! If I only put a stop point on line2,
then the code on line1 executes well but not that code on line2.

I don't know if a kind of "pause" function could be of interest, anyway I
couldn't find one in Visual Basic's help.

Please help me, I'm just about to throw my computer out of the window ! :)

Thanks for it (the computer), and sorry for my approximative english.

Laban.

--
 
D

Douglas J. Steele

See whether calling the DoEvents function between lines 2 and 3 helps. That
passes control back to the operating system, so that it can complete any
outstanding tasks.

Private Sub btn_Click()
Me.btn.Caption = "Process is running" Line1
Me.btn.BackColor = 65535 Line2
DoEvents
Call Procedure1 Line3
Me.btn.Caption = "Process is completed" Line4
Me.btn.BackColor = 16777164 Line5
End Sub
 
T

Tom Collins\(Home\)

Screen updating is often a lower priority than other code running in
the background.
Try putting Me.Repaint in-between lines 2 & 3 to force an update.



| Hi! Happy new year!
|
| I'm facing a strange problem!
| I use ACCESS 2002 with an ACCESS 2000 mdb file.
| I've got a bouton named btn, and here is the code corresponding to
the
| OnClick event :
|
| Private Sub btn_Click()
| Me.btn.Caption = "Process is running" Line1
| Me.btn.BackColor = 65535 Line2
| Call Procedure1 Line3
| Me.btn.Caption = "Process is completed" Line4
| Me.btn.BackColor = 16777164 Line5
| End Sub
|
| Procedure1 takes a few seconds to execute.
|
| The problem is that the code on line1 and line2 is not executed,
unless I
| put a stop point on line2 and line3 !! If I only put a stop point on
line2,
| then the code on line1 executes well but not that code on line2.
|
| I don't know if a kind of "pause" function could be of interest,
anyway I
| couldn't find one in Visual Basic's help.
|
| Please help me, I'm just about to throw my computer out of the
window ! :)
|
| Thanks for it (the computer), and sorry for my approximative
english.
|
| Laban.
|
| --
 
L

Laban Twissel

Hi Todd ! Thanks for your help.
I've just tried your solution. Unfortunately it didn't work. I noticed
that if I put a stop point on the line containing the For instruction,
it doesn't help. The stop point has to be put inside the For loop for
the two lines to be executed.



I am not sure why you are getting the error; however, have you tried a
For loop--maybe it would help to make sure the first two lines take
place. Perhaps the property settings do not get applied until after
the procedure takes place. Nonetheless, here's an idea:

Private Sub btn_Click()
Dim i As Integer

For i = 1 to 2

Me.btn.Caption = "Process is running" Line1
Me.btn.BackColor = 65535 Line2

Next %i

Call Procedure1 Line3
Me.btn.Caption = "Process is completed" Line4
Me.btn.BackColor = 16777164 Line5
End Sub

message Hi!
Happy new year!

I'm facing a strange problem!
I use ACCESS 2002 with an ACCESS 2000 mdb file.
I've got a bouton named btn, and here is the code corresponding to
the OnClick event :

Private Sub btn_Click()
Me.btn.Caption = "Process is running" Line1
Me.btn.BackColor = 65535 Line2
Call Procedure1 Line3
Me.btn.Caption = "Process is completed" Line4
Me.btn.BackColor = 16777164 Line5
End Sub

Procedure1 takes a few seconds to execute.

The problem is that the code on line1 and line2 is not executed,
unless I put a stop point on line2 and line3 !! If I only put a stop
point on line2, then the code on line1 executes well but not that
code on line2.

I don't know if a kind of "pause" function could be of interest,
anyway I couldn't find one in Visual Basic's help.

Please help me, I'm just about to throw my computer out of the
window ! :)

Thanks for it (the computer), and sorry for my approximative
english.

Laban.
--
 
L

Laban Twissel

Eureka!
I tried to put a me.repaint instruction after the two non executed lines,
and it worked.
However this solution isn't very clean...maybe the price to pay for a
language (VBA) that isn't very serious... :)
 
D

Douglas J. Steele

I don't understand why you say that it isn't a clean solution, nor why you'd
say VBA isn't very serious.
 

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