Minggu, 23 April 2017

[MS_AccessPros] Closing a Form with VBA

 

I have a simple three field form. the first two fields are disabled and the third is a combo. I want to test the combo to see if there are any rows in it. If there are no rows, I want to close the form, Undo, and open a different form where rows are added which the combo box can then use.

Private Sub cboSampleSpecID_GotFocus()
 If Me.cboSampleSpecID.ListCount = 0 Then
MsgBox "No specifications have been created for this Location/Application Group." & vbNewLine &        vbNewLine & _
"You will be returned to the Sample Specifications form to create new specifications.", vbOKCancel, gstrAppTitle
DoCmd.Close acForm, "frmSampleGroupSpecification", acSaveNo
DoCmd.OpenForm "frmConfigureSampleSpecDetails", acNormal, , , acFormEdit, acWindowNormal, txtLocationID
End If
End Sub

I get an error message saying I can't do this while processing a form or report event. The DoCmd.Close statement is then highlighted.

I don't know why I can't close the form in this event when I can close it using the same DoCmd as the click event for a command button.





__._,_.___

Posted by: david.pratt@outlook.com
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (1)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.


.

__,_._,___

Tidak ada komentar:

Posting Komentar