Close a form code!

B

Bob Vance

Can i close this form if No seleted.Thanks Bob
If vbNo , DoCmd.Close acForm, "frmZeroAmountHolding"
------------------------------------------------
Private Sub cmdDistributeAllInvoices_Click()

DoCmd.OpenForm "frmZeroAmountHolding"
Dim nRtnValue As Integer

nRtnValue = MsgBox("Are you sure you want to Distribute All Invoices!" &
vbCrLf & vbCrLf & "If you choose Yes, all the Invoices will have Invoice
Numbers!" & vbCrLf & vbCrLf & "Also have you entered all last Months
Payments!", vbCritical + vbYesNo + vbDefaultButton2, "Distribute all
Invoices")
If nRtnValue = vbYes Then
DoCmd.Hourglass True
subSetInvoiceValues
Application.SysCmd acSysCmdSetStatus, "Process is completed."
Application.SysCmd acSysCmdClearStatus
DoCmd.Hourglass False
Me.lstModify.Requery
DoCmd.Close acForm, "frmZeroAmountHolding"

End If
End Sub
 
J

John Spencer MVP

Sure

Private Sub cmdDistributeAllInvoices_Click()

DoCmd.OpenForm "frmZeroAmountHolding"
Dim nRtnValue As Integer

nRtnValue = MsgBox("Are you sure you want to Distribute All Invoices!" &
vbCrLf & vbCrLf & "If you choose Yes, all the Invoices will have Invoice
Numbers!" & vbCrLf & vbCrLf & "Also have you entered all last Months
Payments!", vbCritical + vbYesNo + vbDefaultButton2, "Distribute all
Invoices")
If nRtnValue = vbYes Then
DoCmd.Hourglass True
subSetInvoiceValues
Application.SysCmd acSysCmdSetStatus, "Process is completed."
Application.SysCmd acSysCmdClearStatus
DoCmd.Hourglass False
Me.lstModify.Requery
DoCmd.Close acForm, "frmZeroAmountHolding"
ELSE
DoCmd.Close acForm, "frmZeroAmountHolding"
End If
End Sub

Or even simpler, move the End If before the DoCmd.Close acForm line.

DoCmd.OpenForm "frmZeroAmountHolding"
Dim nRtnValue As Integer

nRtnValue = MsgBox("Are you sure you want to Distribute All Invoices!" &
vbCrLf & vbCrLf & "If you choose Yes, all the Invoices will have Invoice
Numbers!" & vbCrLf & vbCrLf & "Also have you entered all last Months
Payments!", vbCritical + vbYesNo + vbDefaultButton2, "Distribute all
Invoices")
If nRtnValue = vbYes Then
DoCmd.Hourglass True
subSetInvoiceValues
Application.SysCmd acSysCmdSetStatus, "Process is completed."
Application.SysCmd acSysCmdClearStatus
DoCmd.Hourglass False
Me.lstModify.Requery
End if

DoCmd.Close acForm, "frmZeroAmountHolding"

End Sub
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
B

Bob Vance

Thanks John. Brilliant :) regards Bob Vance

John Spencer MVP said:
Sure

Private Sub cmdDistributeAllInvoices_Click()

DoCmd.OpenForm "frmZeroAmountHolding"
Dim nRtnValue As Integer

nRtnValue = MsgBox("Are you sure you want to Distribute All Invoices!"
&
vbCrLf & vbCrLf & "If you choose Yes, all the Invoices will have Invoice
Numbers!" & vbCrLf & vbCrLf & "Also have you entered all last Months
Payments!", vbCritical + vbYesNo + vbDefaultButton2, "Distribute all
Invoices")
If nRtnValue = vbYes Then
DoCmd.Hourglass True
subSetInvoiceValues
Application.SysCmd acSysCmdSetStatus, "Process is completed."
Application.SysCmd acSysCmdClearStatus
DoCmd.Hourglass False
Me.lstModify.Requery
DoCmd.Close acForm, "frmZeroAmountHolding"
ELSE
DoCmd.Close acForm, "frmZeroAmountHolding"
End If
End Sub

Or even simpler, move the End If before the DoCmd.Close acForm line.

DoCmd.OpenForm "frmZeroAmountHolding"
Dim nRtnValue As Integer

nRtnValue = MsgBox("Are you sure you want to Distribute All Invoices!"
&
vbCrLf & vbCrLf & "If you choose Yes, all the Invoices will have Invoice
Numbers!" & vbCrLf & vbCrLf & "Also have you entered all last Months
Payments!", vbCritical + vbYesNo + vbDefaultButton2, "Distribute all
Invoices")
If nRtnValue = vbYes Then
DoCmd.Hourglass True
subSetInvoiceValues
Application.SysCmd acSysCmdSetStatus, "Process is completed."
Application.SysCmd acSysCmdClearStatus
DoCmd.Hourglass False
Me.lstModify.Requery
End if

DoCmd.Close acForm, "frmZeroAmountHolding"

End Sub
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 

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