Debug vs. Execute runs differently

D

dubbglubb

Hey Everyone,

Has anybody come across this before? My Word form code operates as
expected while I'm debugging but not when I execute it.

It's frustrating because I can't see how the code is going wrong.

I'm asking this as a general question before I post code in case
anybody has any general theories on *Debugging vs. Execution*.

Cheers,
 
D

Doug Robbins - Word MVP

You will have to post the code if you expect to get any assistance.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
T

That Guy

Hey Everyone,

Has anybody come across this before? My Word form code operates as
expected while I'm debugging but not when I execute it.

It's frustrating because I can't see how the code is going wrong.

I'm asking this as a general question before I post code in case
anybody has any general theories on *Debugging vs. Execution*.

Cheers,

I have found that things like this can happen when you are doing
asynchronous operations. For example one time I was using a word macro
to generate a concatenated PDF of the file I was working on, and other
files that I had already made. I found that while I debugged the code
it worked great but during execution, because I was not stepping
through line by line and the application was allowed to move as it
wanted to without halting, the files were printing to the PDF printer
much to slowly and not in sync with my application. You see when they
were printing in the background, word was not waiting for them to
finish printing to start trying to concatenate them. This obviously
lead to issues.

So I would check the synchronization of your operations. Perhaps
during debug the app is waiting for a file to open or be created and
whil it is executing it is not.

just a thought.
 
D

dubbglubb

Thanks guys,

I had a hunch about what was causing the problem, which boils down t
this event:


Code
-------------------


Private Sub tgNataOnOff_AfterUpdate()

'If the user turns NATA On or Off then the Nata label changes & appropriate signatories are toggled

If tgNataOnOff.Value = True Then
lblNata.Caption = "N"
Signatory2On
If Trim(txtSignatoryTitle1.Text) = "Client Manager" Then
txtSignatoryTitle1.Text = "NATA Signatory"
End If

ElseIf tgNataOnOff.Value = False Then
lblNata.Caption = ""
Signatory2Off
If Trim(txtSignatoryTitle1.Text) = "NATA Signatory" Then
txtSignatoryTitle1.Text = "Client Manager"
End If
End If

End Sub

-------------------


This particular event is not triggered during Initialization as I'
debugging, but only when the user toggles tgNataOnOff. Yet is does ru
when the form is Executed.

If I changed the event to:


Code
-------------------

Private Sub tgNataOnOff_Click()

-------------------


...It works as desired. ie. That event only triggers when the use
toggles it and not during initialization

I don’t really get the difference. After all, aren’t both event
supposed to be triggered by the user?

I have noticed that *Click* events can get triggered when a toggl
button *.value *property is changed in VBA, so I’d converted them t
*AfterUpdate* events.

I haven’t yet found a very good explanation of event hierarchies an
triggers for toggle buttons. Does anybody know more about these events


Cheers
 
T

That Guy

..It works as desired. ie. That event only triggers when the user
toggles it  and not during initialization  

I don’t really get the difference. After all, aren’t both events
supposed to be  triggered by the user?

I have noticed that *Click* events can get triggered when a toggle
button *.value *property is changed in VBA, so I’d converted them to
*AfterUpdate* events.

I haven’t yet found a very good explanation of event hierarchies and
triggers for toggle buttons. Does anybody know more about these events?

Now I can't speak for all events but I have found a few that do not
behave as intuitively as you would think they do., After_Update is one
of them.

After_update fires every time the control is updated which happens
when it is changed even if the form is the party changing it. Another
example is the Activate event of a form. I have found this code fires
every time a form gets focus, not just when it starts or is
initialized. So if you hide a form but don't unload it the next time
you bring focus to it, it's Activate event is fired.

I do not know of a hierarchy per say but I am sure if you spend time
in the MSDN library searching about it you should be able to find when
each kind of event is fired, I only point this out because it seems as
though you believe some events to take precedence over others when the
case is that some events simply fire before others and thus end up on
the stack first.

Hope that helps.
 
D

dubbglubb

I do not know of a hierarchy per say but I am sure if you spend time
in the MSDN library searching about it you should be able to find when
each kind of event is fired, I only point this out because it seems as
though you believe some events to take precedence over others when the
case is that some events simply fire before others and thus end up on
the stack first.

Hope that helps.

Thanks That Guy.

Yeah, I have spent some time on MSDN and have yet discovered inf
specific to VBA toggle events. Maybe I'm just seraching with thrw worn
terms. I guess by "hierarchy" I'd meant -Event Order -(or something).

Anyway what I was hoping to find was an explanation of how event
differ from, supersede, follow or precede other events.
ie. The Click Event does -this-, whereas the AfterUpdate Event doe
-that-.

More specifically, I'd like the most appropriate event for toggl
buttons as triggered by the user.

Cheer
 
T

That Guy

More specifically, I'd like the most appropriate event for toggle
buttons as triggered by the user.

I think that would be the click event. A simple example of this is
adding 'msgbox ToggleButton.value' to the click sub. You will see that
every time you click it the event fires.

As for the event structure. I am not sure where you can find this
info. If you ever do though please share it with the rest of us. I
have had to figure a lot of it out by trial and error because I have
been unsuccessful in finding this also.

Have fun.
 

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