Senin, 24 April 2017

Re: [MS_AccessPros] Closing a Form with VBA

 

There is a table of sample Groups and a table of Specifications.  The form is used to change the specification that is associated with the Sample Group.  The combo can be empty if no specifications were ever created for the Sample Group.  In that case I want to redirect the User to a form where the specifications are created.

The first two fields are disabled because the values for them are provided by the calling form.  The calling form is an unbound form where I have a list box of the sample groups and a related text box where I display the associated specification.  The associated specification can be changed by 2clicking on the Sample Group and thus bringing up the form in question.

I was hoping there was a quick, easy answer (always the hope) for why Access would not allow me to close the form during this Event (GotFocus) processing but it does allow me to close a form with the Click event of a command button.

After describing this, perhaps my logic is wrong.  Perhaps I should somehow check for existing specifications at the 2Click event of the calling form? I currently do not have a "named query" that is used for the combo box.  A SQL statement is used for the row source of the combo box.

If it is a complicated answer, just hold off until I do some more experimenting.  I don't want to waste your time.


---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :

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@... [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: david.pratt@outlook.com
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (3)

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