Minggu, 23 April 2017

Re: [MS_AccessPros] Closing a Form with VBA

 

David-

I don't think I've ever used GotFocus.  

What are you trying to do with this form?  Why are the other two controls disabled?  Why would the combo box have zero rows?  How is the form opened?  What other code is there in the form?

John Viescas, author
Effective SQL
SQL Queries for Mere Mortals
Microsoft Office Access 2010 Inside Out
Microsoft Office Access 2007 Inside Out
Building Access Applications

On Apr 24, 2017, at 00:12, david.pratt@outlook.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

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: John Viescas <johnv@msn.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)

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