Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Coding Problem

Status
Not open for further replies.

ddmtn546

Technical User
Dec 20, 2000
38
US
Included below is my vbcode. The code is initiated from a button on a form. It pops-up another box asking the operator if it is OK to proceed or Cancel. Problem - when Cancel is requested the code terminates fine, however, when OK is hit the vb code window opens. Am I not terminating the code correctly? Is there another way to accomplish this? Thanks in advance.

Private Sub UpdateDisp_click()
Dim sMsgReply As String
sMsgReply = MsgBox("Hit OK to make changes or CANCEL to quit.", vbOKCancel, "Caution! - toggles & updates ALL outages to Dispatched.")
If sMsgReply = vbOK Then
DoCmd.RunMacro ("UpdateDisp Macro")
Else
DoCmd.CancelEvent
End If
End Sub

 
What's calling this function in the first place?
Also if you are using VB"A" (Visual Basic for Applications) then you could do whatever is in your macro with VBA code too. Then eliminate the macro altogether.
DougP, MCP
dposton@universal1.com

Ask me how Bar-codes can help you be more productive.
Or visit my WEB site
 
I agree with Doug. Macros limit your capabilities and do NOT allow error checking. Access has a wizard to change macros to code. You may want to use it on 'UpdateDisp Macro". Anyway, I've always felt the direct approach is the best on MsgBox function.

Another way of finding out what is causing your problem is to use debugging techniques or error checking. To debug select the 'Resume ExitProc' line and hit F9. Then run the application and it will trap on the line. When it stops put the cursor on the 'Resume' line and push Ctrl F9. The processing will move to resume, then pressing F8 will process the resume line and move back to the line that failed so you can use the debug or immediate window determine what the problems could be. Another method would be to set a checkpoint at the first processing line and press F8 to take line-by-line steps.


Private Sub UpdateDisp_click()

On Error GoTo HandleErr

If MsgBox("Hit OK to make changes or CANCEL to quit.", vbOKCancel, "Caution! - toggles & updates ALL outages to Dispatched.") = vbOK Then
DoCmd.RunMacro ("UpdateDisp Macro")
Else
DoCmd.CancelEvent
End If

ExitProc:
Exit Sub

HandleErr:

MsgBox "Error " & Err.Number & " Description: " & Err.Description
Resume ExitProc
Resume

End Sub
 
Do you even need the "DoCmd.CancelEvent"?

It would seem that if OK is not the response to the msg box the code will just drop through to the exit.

Larry De Laruelle
larry1de@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top