[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 134
  • Last Modified:

Line of code being executed more than one time

I have a line of code being executed more then one time the code is in a click event of a command button.

private sub cmdButton_Click()
   action
end sub

When I click the button the desired the line of code is processed and the action takes place but shortly thereafter the line of code is processed again.

I have modified the event as such.

private sub cmdButton_Click()
   msgbox "Test",vbokonly
   action
end sub

I then brake the code at the action line.
When I click the button:
  The message box is displayed
  VB stops processing code at the action line
  I click the start button
  The d the line of code is processed and the action takes place
  shortly thereafter VB stops processing at the action line again but the msgbox is not displayed

This tells me that nothing else is calling the click event because if that was the case the msgbox would have been displayed again.  For some reason the action line of code is being processed two times.
0
MERCOMMS
Asked:
MERCOMMS
  • 3
  • 2
1 Solution
 
PaulHewsCommented:
Is the action sub calling itself?
0
 
PaulHewsCommented:
Put a breakpoint at the top of the action sub.  Run the project and click the button.  When it hits the breakpoint the first time, hit F5.  When it hits it the second time, hit Ctrl-L to bring up the call stack.  This should show you where the sub is being called from.
0
 
MERCOMMSAuthor Commented:
The breakpoint is not being reached a second time.

Actual Code

Private Sub cmdContinue_Click()
    msgbox "Testing",vbokonly
    frmSelectShip.show
    me.hide
end sub

I put a breakpoint on the frmSelectShip.show line

I click the button and
1.  I get the message box and click the OK button.
2.  VB stops at the frmselectship.show line.  I click the start button.
3.  frmselectship is shown.  frmselect ship does something then calls another form that unloads frmselectship.
4.  Error is generated when frmselectship.show runs again because it has been unloaded.  But VB does not break again it just tries to runs the line of code (it does break the first time, step 2 above)



0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
PaulHewsCommented:
Sounds odd.  Does frmSelectShip have a lot of processing code in Form_Load, or does it just wait for input?
0
 
MERCOMMSAuthor Commented:
"Sounds odd.  Does frmSelectShip have a lot of processing code in Form_Load, or does it just wait for input?"

If one condition is met it loads another form that then calls a batch file as another user using CreateProcessWithLogon.

0
 
EDDYKTCommented:
>>frmselectship is shown.  frmselect ship does something then calls another form that unloads frmselectship.

How do you unload your frmselectship?
If you want to have one one frmselectship showed at one time

you should use

public frm as  frmSelectShip ' declare in public module

Private Sub cmdContinue_Click()
    msgbox "Testing",vbokonly
    set frm = new frmSelectShip
    frm.show
    me.hide
end sub


to unload
unload frm
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now