SetFocus 2110 error

Users are entering invoices in a subform and after the vendor name is populated two things happen.  1. the vendor number is populated in the field VendorNo and 2. another form open with a list of open purchase orders for that vendor.  All if fine until I try to move the focus back to the original subform.  Here's my code:

Private Sub VendorName_AfterUpdate()
    VendorNo = VendorName.Column(2)
    Forms!InvoiceEntry.VN = VendorNo
    If isAdmin_AP() = False Then
        DoCmd.OpenForm "PODetails"
        Forms!PODetails.Requery
        Forms!InvoiceEntry!InvoiceEntry_sf_Invoices.SetFocus
        Forms!InvoiceEntry!InvoiceEntry_sf_Invoices.Form.VendorNo.SetFocus
    Else
    End If
 
End Sub

Thanks.

wellesleydpwAsked:
Who is Participating?
 
Dale FyeCommented:
It looks like you are trying to, after opening the PODetails form, set the focus back into the VendorNo field, of the subform, on the form that originally had the focus.  What is the purpose of popping up the PODetails form, if you are just going to set the focus back to a control on the subform, of the InvoiceEntry form?

if the PODetails form is not already open when you do the DoCmd.Openform "PODetails", thenyou don't need the requery line.  That action is automatically performed when you open the form.  If PODetails is already open then you might try the changes I've indicated below.

Assuming this is really what you want to do, then you might want to try setting the focus to the InventoryEntry form before setting it to the subform.

Private Sub VendorName_AfterUpdate()
    VendorNo = VendorName.Column(2)
    Forms!InvoiceEntry.VN = VendorNo
    If isAdmin_AP() = False Then

        'if PODetails is already open, then requery it, otherwise open it
        If Currentproject.allforms("PODetails").IsLoaded then
             Forms!PODetails.Requery
             Forms!PODetails.Visible = true
        Else
             DoCmd.OpenForm "PODetails"
        End If

        Forms!InvoiceEntry.SetFocus        
        Forms!InvoiceEntry!InvoiceEntry_sf_Invoices.SetFocus
        Forms!InvoiceEntry!InvoiceEntry_sf_Invoices.Form.VendorNo.SetFocus
    End If
 
End Sub

0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Make sure that you're setting the focus to the Subform CONTROL. This may or may not be named the same as the Form you're using as a SourceObject for that control.

To determine the name of the control, open the main form in Design view, and select the Subform (click it ONCE). Review the Properties dialog - do you see a Property named Source Object? If you do, then you've correctly selected the Subform CONTROL, and you'd use whatever value you find in the Name property of that control in your code.

See this KB article: http://support.microsoft.com/kb/294212
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I should have written:

Make sure that you're setting the focus to the Subform CONTROL before you try to SetFocus to the data entry control.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
mbizupCommented:
<< Forms!InvoiceEntry!InvoiceEntry_sf_Invoices.Form.VendorNo.SetFocus >>

Are you using the right control name?  Your AfterUpdate event is for a different control - VendorName.


If VendorNo is hidden, locked, etc you will encounter problems with SetFocus.

Also, if your code is running from the subform that VendorNo (or VendorName) resides on, you don't need the full reference, just:

Me,VendorNo.SetFocus

(or Me.VendorName.SetFocus)
0
 
wellesleydpwAuthor Commented:
thank you all.  
LSM: The name of the subform control is the same as the subform.  
fyed: I've used your recommendation and set the focus to the main form and then the subform
mbizup, I changed the focus to Vendor Name and everything works!  But I would like to set the focus to VendorNo. It's not hidden or locked.  Are there other settings that could hinder this?
0
 
mbizupCommented:
wellesleydpw,

<It's not hidden or locked.  Are there other settings that could hinder this? >

My best guesses would be any setting that might prevent manual data entry - hidden, locked, disabled, or a control source along the lines of:

 = VendorName.Column(2)   <--- A control source like this will block manual data entry


However, if your actual code is exactly as posted:

>>>     VendorNo = VendorName.Column(2)

Then it appears that you have a regular bound control.

Are your textbox and field name both the same?  ie: both are "VendorNo"?

If so, try this:

        Forms!InvoiceEntry!InvoiceEntry_sf_Invoices.Form.Controls("VendorNo").SetFocus

and again, if this code is running from the subform, you can shorten it to this:

       Me.Controls("VendorNo").SetFocus

0
 
wellesleydpwAuthor Commented:
thank you all. I still can't get the focus to the field that I want but I can get it to another which will have to do.
I'm giving fyed the most points because I had to set the focus to the main form first and then then subform and then the control.
0
 
mbizupCommented:
<I had to set the focus to the main form first and then then subform and then the control. >

Isn't that what LSMConsulting suggested earlier in the second post?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.