Yes No Message box

S

Steve

Sorry for the stupid question, but I am loosing altitude on this.

I have created a message bx yes/no, the yes part works because it just
continues to run the code, but when "No" is clicked I want it to close and
not continue.
Here is the code, any help would be greatly appreciated.
Thank you in advance

Private Sub Command45_Click()
On Error GoTo Command45_Click_Err
RetValue = MsgBox(" Are You Creating a FY 07 SOW?", vbYesNo)
DoCmd.OpenForm "FY2001", acNormal, "", "", acEdit, acNormal
DoCmd.maximize


Command45_Click_Exit:
Exit Sub

Command45_Click_Err:
MsgBox Error$
Resume Command45_Click_Exit

End Sub
 
D

Douglas J. Steele

If MsgBox(" Are You Creating a FY 07 SOW?", vbYesNo) = vbYes Then
DoCmd.OpenForm "FY2001", acNormal, "", "", acEdit, acNormal
DoCmd.maximize
End If
 
O

Ofer Cohen

Try this

Private Sub Command45_Click()
On Error GoTo Command45_Click_Err
if MsgBox(" Are You Creating a FY 07 SOW?", vbYesNo)=vbYes then
DoCmd.OpenForm "FY2001", acNormal, "", "", acEdit, acNormal
DoCmd.maximize
End If


Command45_Click_Exit:
Exit Sub

Command45_Click_Err:
MsgBox Error$
Resume Command45_Click_Exit

End Sub
 
F

fredg

Sorry for the stupid question, but I am loosing altitude on this.

I have created a message bx yes/no, the yes part works because it just
continues to run the code, but when "No" is clicked I want it to close and
not continue.
Here is the code, any help would be greatly appreciated.
Thank you in advance

Private Sub Command45_Click()
On Error GoTo Command45_Click_Err
RetValue = MsgBox(" Are You Creating a FY 07 SOW?", vbYesNo)
DoCmd.OpenForm "FY2001", acNormal, "", "", acEdit, acNormal
DoCmd.maximize

Command45_Click_Exit:
Exit Sub

Command45_Click_Err:
MsgBox Error$
Resume Command45_Click_Exit

End Sub


I don't know what you mean by 'close' when No is clicked.
I suspect you do not mean close the form or application, but rather
just don't do anything.

Private Sub Command45_Click()
On Error GoTo Command45_Click_Err
If MsgBox(" Are You Creating a FY 07 SOW?", vbYesNo) = vbYes Then
DoCmd.OpenForm "FY2001"
DoCmd.maximize
End If

Command45_Click_Exit:
Exit Sub

Command45_Click_Err:
MsgBox Error$
Resume Command45_Click_Exit

End Sub


Note: acNormal, "", "", acEdit, acNormal each of these arguments are
the default, so there is no need to explicitly state them.

If you did wish to close the form or application if No was selected,
you would do it this way:

If MsgBox(" Are You Creating a FY 07 SOW?", vbYesNo) = vbYes Then
DoCmd.OpenForm "FY2001"
DoCmd.maximize
Else
DoCmd.Quit ' (to close the application)
' or DoCmd.Close acForm, Me.Name (to close just this form)
End If
 
T

tigerlilly

Try using a "if then else" statement to handle the arguments. I believe the
value of vbYes is 6 and VbNo is 7.

If retvalue = 6 then
DoCmd.OpenForm "FY2001", acNormal, "", "", acEdit, acNormal
DoCmd.maximize
else
exit sub
end if

One other suggestion.... I noticed you used generic names for your
control. Try using standard naming conventions on your objects (framse,
button, text fields, labels, etc) that relate to the corresponding tast or
data elemement.

(i.e., command45 could be cmdOpenFY2001). You'll find out later that
this will help anyone who works on this application in the future to locate
items in code vs having to find the object in design, clicking it, then
trying to find the corresponding code function.
 
D

Douglas J Steele

In my opinion, you're better off comparing to vbYes or vbNo, rather than the
number. It's far clearer to others reading the code.
 

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

Similar Threads


Top