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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close form on vbCancel

Status
Not open for further replies.

lastout

Programmer
Apr 12, 2002
84
US
The following If...Then block is supposed to perform different commands on form based on whether the user clicks vbYes, vbNo, or vbCancel. It all works except for the vbCancel. If the user clicks vbCancel, I want the form to close. What happens instead is that the MsgBox closes and the focus goes to the form. Can anyone tell me what I'm doing wrong here? Many thanks in advance!

If intEntityID <> intPREntityID Then
If MsgBox(Msg, vbQuestion + vbYesNoCancel + vbDefaultButton2) = vbYes Then
DoCmd.GoToRecord , , acNewRec
DoCmd.Maximize
Forms!frmPartnersRelations!EntityID = Me.EntityID
Forms!frmPartnersRelations!ProjectID = Me.ProjectID
ElseIf vbNo Then
DoCmd.GoToRecord , , acFirst
DoCmd.Maximize
Else
DoCmd.CancelEvent
DoCmd.Close
End If
End If lastout (the game's not over till it's over)
 
Keep code simple. Do an if catch with vbCancel before doing the checks for yes/no. This makes is much easier when you look at your code six years later even tho it may not seem as elegant!!!

Rollie
 
Rollie,

Thanks for responding. I'm not sure what you mean by an if catch. If it isn't too much trouble, could you give me a simple example? THANKS! lastout (the game's not over till it's over)
 
Dim yes as integer

yes = msgbox ( 'all that stuff)
if not (yes = vbCancel) then
if (yes = vbYes) then
somestuff cause it means yes
else
somestuff cause it must be no
endif
endif

 
By the way, the answer to your question, &quot;What did I do wrong' is the logical there which is only 'vbNo.' vbNo is a constant which translates to the integer 6 (i believe). It never is anything else. 6 is always true in boolean math.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top