Code works in debug only

J

Jimbo213

I've got the below field in a table, and placed on a form as a text box.

I've got a pushbutton that OnFocus fires some VBA code, the first step is

Me.CalculatingMessage = "Calculating Score"

The calculating routine takes about 3 seconds, and at the end of the routine
I have

Me.CalculatingMessage = "Calculation Done"

In the VBA code, when I set the breakpoint at this line, and F8 into it, the
text message shows. When I F5 to the ending message, it also displays
properly.

When I remove the breakpoint, neither messages show.

Any Ideas what I'm doing wrong?

Thanks for your reply & assistance.
Jimbo213
 
J

Julia B

Where do you want the messages to show? As far as I can see you're just
setting a variable 'CalculatingMessage', which will be set regardless of
whether you're in debug mode or not. However you only see it being done in
debug mode. If you want to see it somewhere, then you need to display it
somehow, either as a message box or in a label, e.g.

me.CalculatingMessage = "Calculating Score"
msgbox me.CalculatingMessage
lblMessage.Caption = me.CalculatingMessage

' do calculations

me.CalculatingMessage = "Calculation Done"
msgbox me.CalculatingMessage
lblMessage.Caption = me.CalculatingMessage

Hope this helps.
Julia
 
J

Jimbo213

See first line of my post

the field is ... "placed on a form as a text box"

I need the message to show on the form.

Thanks for your reply & assistance.
Jimbo213
 
J

Julia B

Sorry, I'm a bit confused by that. I assumed CalculatingMessage was a variable.
Is it data you want to save to a table or display to the user?

If it's the latter, which I assume it is, then you don't need a field in a
table or a textbox, just a label will suffice.

If I've misunderstood, please post back explaining what you need to do.

Julia
 
J

Jimbo213

Hi Julia and thanks for your support.

To Answer you question:
Display to the user on form only. I don't really need it in the table. I
first tried manipulating an UNBOUND text box with the code but that didn't
work so I created the field in the table.

I didn't know you could assign a value to a label? Is that what you meant
for me to do?


In the below code, the "Calculate Complete" DOES SHOW on the form.

However "Calculating Score" only shows on the form when I put the breakpoint
[F9] at the Me.Dirty statement. Only then does "Calculating Score" show on
the form.

Note: The calculation of the seven call statements takes 3 seconds so I
know the code isn't executing so fast that I blink and miss the "Calculating
Score" message.

Thanks for continuing to help. Jim.

------------ full code follows -------------------
Private Sub CalcStatus_Click()
' CALC button on Status tab - fires all seven CalcStatus_XXX code

Me.CalculatingMessage.Value = "Calculating Score"

Me.Dirty = False 'causes a COMMIT
Form_frmD7MASTER.Refresh

Me.CalculatingMessage.Value = "Calculating Score"

Call CalcStatus_EIA
Call CalcStatus_DATA
Call CalcStatus_FIT
Call CalcStatus_WAVE
Call CalcStatus_PERF
Call CalcStatus_ENV
Call CalcStatus_IMPL

Call Update_Status

Me.CalculatingMessage.Value = "Calculate Complete"

Me.Dirty = False 'causes a COMMIT
Form_frmD7MASTER.Refresh

'Keeps form from cycling
Me.ParkingSpot.SetFocus

End Sub
----------------- full code ----------------------

Thanks for your reply & assistance.
Jimbo213
 
J

Julia B

Jim

I'm not sure, but it might be this:

Me.Dirty = False 'causes a COMMIT Form_frmD7MASTER.Refresh

The form is refreshed immediately after the message is displayed, so it will
probably clear the value in the field, i.e. it IS working but it's so there
and gone so quickly you don't see it.

I would definitely recommend not having the field in the table or a textbox
linked to it. It's an unecessary overhead. It's much better to have a label
and set it's caption, as per my example.

I would remove the form refresh and see if that makes a difference.

Julia

Jimbo213 said:
Hi Julia and thanks for your support.

To Answer you question:
Display to the user on form only. I don't really need it in the table. I
first tried manipulating an UNBOUND text box with the code but that didn't
work so I created the field in the table.

I didn't know you could assign a value to a label? Is that what you meant
for me to do?


In the below code, the "Calculate Complete" DOES SHOW on the form.

However "Calculating Score" only shows on the form when I put the breakpoint
[F9] at the Me.Dirty statement. Only then does "Calculating Score" show on
the form.

Note: The calculation of the seven call statements takes 3 seconds so I
know the code isn't executing so fast that I blink and miss the "Calculating
Score" message.

Thanks for continuing to help. Jim.

------------ full code follows -------------------
Private Sub CalcStatus_Click()
' CALC button on Status tab - fires all seven CalcStatus_XXX code

Me.CalculatingMessage.Value = "Calculating Score"

Me.Dirty = False 'causes a COMMIT
Form_frmD7MASTER.Refresh

Me.CalculatingMessage.Value = "Calculating Score"

Call CalcStatus_EIA
Call CalcStatus_DATA
Call CalcStatus_FIT
Call CalcStatus_WAVE
Call CalcStatus_PERF
Call CalcStatus_ENV
Call CalcStatus_IMPL

Call Update_Status

Me.CalculatingMessage.Value = "Calculate Complete"

Me.Dirty = False 'causes a COMMIT
Form_frmD7MASTER.Refresh

'Keeps form from cycling
Me.ParkingSpot.SetFocus

End Sub
----------------- full code ----------------------

Thanks for your reply & assistance.
Jimbo213


Julia B said:
Sorry, I'm a bit confused by that. I assumed CalculatingMessage was a variable.
Is it data you want to save to a table or display to the user?

If it's the latter, which I assume it is, then you don't need a field in a
table or a textbox, just a label will suffice.

If I've misunderstood, please post back explaining what you need to do.

Julia
 
D

Dirk Goldgar

Jimbo213 said:
I've got the below field in a table, and placed on a form as a text box.

I've got a pushbutton that OnFocus fires some VBA code, the first step is

Me.CalculatingMessage = "Calculating Score"

The calculating routine takes about 3 seconds, and at the end of the
routine
I have

Me.CalculatingMessage = "Calculation Done"

In the VBA code, when I set the breakpoint at this line, and F8 into it,
the
text message shows. When I F5 to the ending message, it also displays
properly.

When I remove the breakpoint, neither messages show.

Any Ideas what I'm doing wrong?


It seems likely that your code isn't giving Access a chance -- or reason --
to redraw the screen. Try inserting the statement "DoEvents" after changing
the text box at the beginning of the routine:

Me.CalculatingMessage = "Calculating Score"
DoEvents

If that doesn't work, you could try Me.Repaint, but I think DoEvents ought
to do it.
 
J

Jimbo213

JuliaB - that's neat - I didn't know you could set the value of a label.

I used your code [with the label, not the message box] but it still blows-by
the first code. It DOES CORRECTLY show "calculation complete" so I'm 1/2 way
there =;)

I've tried commenting-out the Me.Dirty and refresh - that doesn't seem to
make a difference.

------------ code ---------------
Private Sub CalcStatus_Click()
' CALC button on Status tab - fires all seven CalcStatus_XXX code

LabelCalculateMsg.Caption = "Calculating Score"

Me.Dirty = False 'causes a COMMIT
Form_frmD7MASTER.Refresh

Call CalcStatus_EIA
Call CalcStatus_DATA
Call CalcStatus_FIT
Call CalcStatus_WAVE
Call CalcStatus_PERF
Call CalcStatus_ENV
Call CalcStatus_IMPL

Call Update_Status

LabelCalculateMsg.Caption = "Calculation Complete"

Me.Dirty = False 'causes a COMMIT
Form_frmD7MASTER.Refresh

'Keeps form from cycling
Me.ParkingSpot.SetFocus

End Sub
------------ code ---------------


Thanks for your reply & assistance.
Jimbo213
 
J

Jimbo213

Dick. Thanks for the suggestion which I've tried.

Neither DoEvents nor Me.Repaint slowed it down enough to show the
"Calculating Score" message - which I've now put in a label per JulieB
suggestion.

To make DoEvents or Me.Repaint work do I need to go back to the textbox?

Thanks for your reply & assistance.
Jimbo213
 
J

Jimbo213

Julia - the msgbox does work. It shows as a popup with OK button AND the
text DOES CORRECTLY show in the label. Hurray.

Is there any way to make this display without the popup?

Thanks for your reply & assistance.
Jimbo213
 
D

Dirk Goldgar

Jimbo213 said:
Dick. Thanks for the suggestion which I've tried.

Neither DoEvents nor Me.Repaint slowed it down enough to show the
"Calculating Score" message - which I've now put in a label per JulieB
suggestion.

To make DoEvents or Me.Repaint work do I need to go back to the textbox?


Absolutely not! Though an *unbound* text box ought to work as well as a
label. Still, there's no reason to use a text box when a label will
suffice.

What was the exact code you tried? I tried this simple code on a test form
and it worked fine:

'----- start of example code from test form -----
Dim t As Single

Me.lblCalculatingMessage.Caption = "Calculating Score"
DoEvents

' Here we simulate a tight processing loop.
t = Timer() + 5
Do Until Timer() > t
Loop

Me.lblCalculatingMessage.Caption = "Done!"

'----- end of example code from test form -----
 
J

Jimbo213

Actual code in 6:32am and 7:15am msg to JuliaB.

It is really strange, Dick, but now the label is changing correctly using
the code shown to Julia.

I'll close this post.
Thanks for the timing-loop code.
 
J

Jimbo213

Julia & Dici - I've played with variations on your code suggestion and got
it to work.

Thanks so much for your reply & assistance.
Jimbo213
 
D

Dirk Goldgar

Jimbo213 said:
Actual code in 6:32am and 7:15am msg to JuliaB.

Well, no, because those posts don't have any DoEvents or Me.Repaint
statements, so I can't see where you put them when you tried them.
It is really strange, Dick, but now the label is changing correctly using
the code shown to Julia.

Then all is well now, I guess.
Thanks for the timing-loop code.

You're welcome. I hope you understand, that wasn't intended to serve any
actual purpose; it was just there in my test form to simulate the code you
are running in your Call CalcStatus_xxx routines.
 
B

Bob Quintal

JuliaB - that's neat - I didn't know you could set the value of a
label.

I used your code [with the label, not the message box] but it
still blows-by the first code. It DOES CORRECTLY show
"calculation complete" so I'm 1/2 way there =;)

I've tried commenting-out the Me.Dirty and refresh - that doesn't
seem to make a difference.
Refreshing the screen is done by the OS, not the Access application.
Because Access is busy doing the calculations, it doesn't allow the
OS to repaint the screen until all the calcs are finished.

To resolve this you use the DoEvents statement. I've added some to
your code below. You should also be able to rewmove the redundant
me.dirty = false statements.
 

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