?
Solved

SetFocus 2110 error

Posted on 2011-10-06
8
Medium Priority
?
325 Views
Last Modified: 2012-05-12
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.

0
Comment
Question by:wellesleydpw
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 85
ID: 36923691
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
 
LVL 85
ID: 36923696
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
 
LVL 61

Expert Comment

by:mbizup
ID: 36923833
<< 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 49

Accepted Solution

by:
Dale Fye earned 1600 total points
ID: 36924087
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
 

Author Comment

by:wellesleydpw
ID: 36925795
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
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 400 total points
ID: 36926985
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
 

Author Closing Comment

by:wellesleydpw
ID: 36954884
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
 
LVL 61

Expert Comment

by:mbizup
ID: 36954953
<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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question