+ Reply to Thread
Results 1 to 4 of 4

Error 2110 - can't move focus

Hybrid View

  1. #1
    Registered User
    Join Date
    08-27-2014
    Location
    Albany, NY
    MS-Off Ver
    Office 2010
    Posts
    91

    Error 2110 - can't move focus

    I cannot for the life of me figure out why this error pops up for one user and not others. Basic gist: I have a user-form that the user fills out, and clicks update. Upon clicking update the form asks "Would you like to update another record?". If the user answers vbYes the line of code is currProvNum.SetFocus to start over. However this error pops up consistently for random users. here is the code around the error, The file is quite big so if it needed I will post it, but for now just the code:

    Option Explicit
        'Declare module level variables
        
        Dim bNormalProcess As Boolean
        Dim facilityNameValid As Boolean
        Dim congDistNumValid As Boolean
        Dim congDistNameValid As Boolean
        Dim netSysIdNameValid As Boolean
        Dim netSysIdNumValid As Boolean
        Dim custGroupCodeNameValid As Boolean
        Dim custGroupCodeNumValid As Boolean
        Dim temp As String
        
    
    
    'Sets up the userform and defines the values of the drop down menus, then sets Boolean variables
    'for the validation at the end of the inputs
    
    
    Private Sub UserForm_Initialize()
       'Initialize variables
        Me.updateButton.Enabled = False
        Me.cancelButton.Enabled = True
        facilityNameValid = False
        congDistNumValid = False
        congDistNameValid = False
        netSysIdNameValid = False
        netSysIdNumValid = False
        custGroupCodeNameValid = False
        bNormalProcess = True
        Dim rngColumn1 As Range
        Dim ws As Worksheet
        Application.ScreenUpdating = False
    
    
        ' Populate combo box list that will expand as the range expands.
         Set ws = Worksheets("Master_list")
         
         For Each rngColumn1 In ws.Range("_Col1")
            Me.currProvNum.AddItem rngColumn1.Value
         Next rngColumn1
         
         'sort control ComboBox  Pass the control to the subroutine for sorting
         SORTCB Me.currProvNum
         
         'Define the ranges for dropdowns
         Me.OpenClosedCombo.List = Worksheets("Sheet2").Range("B1:B2").Value
         
         Application.ScreenUpdating = True
    lbl_exit:
        Exit Sub
    End Sub
    
    'On exit of the first selection box, makes sure there is a value there (even blank) then continues to
    'fill the text boxes based on the choice made in the first box.
    
    Private Sub currProvNum_exit(ByVal Cancel As MSForms.ReturnBoolean)
        If currProvNum.ListIndex > -1 Then
            Dim ws As Worksheet
            Set ws = Worksheets("Master_list")
            
            
          
                ' set the text box values with corresponding places on the spreadsheet based on combo box.
                With Me
                    .facilityName.Value = ws.Cells(.currProvNum.ListIndex + 5, 3)
                    .congDistNum.Value = ws.Cells(.currProvNum.ListIndex + 5, 4)
                    .congDistName.Value = ws.Cells(.currProvNum.ListIndex + 5, 5)
                    .netSysIdNum.Value = ws.Cells(.currProvNum.ListIndex + 5, 6)
                    .netSysIdName.Value = ws.Cells(.currProvNum.ListIndex + 5, 7)
                    .custGroupCodeNum.Value = ws.Cells(.currProvNum.ListIndex + 5, 8)
                    .custGroupCodeName.Value = ws.Cells(.currProvNum.ListIndex + 5, 9)
                    .OpenClosedCombo.Value = ws.Cells(.currProvNum.ListIndex + 5, 10)
                    
                    'Store the address values for each control in the .Tag attribute
                    '(False, False) stores the address as 'A1' instead of '$A$1'
                    .currProvNum.Tag = ws.Cells(.currProvNum.ListIndex + 5, 1).Address(False, False)
                    .facilityName.Tag = ws.Cells(.currProvNum.ListIndex + 5, 3).Address(False, False)
                    .congDistNum.Tag = ws.Cells(.currProvNum.ListIndex + 5, 4).Address(False, False)
                    .congDistName.Tag = ws.Cells(.currProvNum.ListIndex + 5, 5).Address(False, False)
                    .netSysIdNum.Tag = ws.Cells(.currProvNum.ListIndex + 5, 6).Address(False, False)
                    .netSysIdName.Tag = ws.Cells(.currProvNum.ListIndex + 5, 7).Address(False, False)
                    .custGroupCodeNum.Tag = ws.Cells(.currProvNum.ListIndex + 5, 8).Address(False, False)
                    .custGroupCodeName.Tag = ws.Cells(.currProvNum.ListIndex + 5, 9).Address(False, False)
                    .OpenClosedCombo.Tag = ws.Cells(.currProvNum.ListIndex + 5, 10).Address(False, False)
                             
                    'marks the row - used in testing
                    temp = CStr(.currProvNum.ListIndex + 5)
                     
                     facilityName.SetFocus
                     
                End With
        End If
        
       
    End Sub
    
    
    Private Sub cancelButton_Click()
        Unload UserForm1
        MsgBox "No Changes were made to the selected record."
    End Sub
    
    'Runs the routine to put all the information back in the appropriate tagged cells (changed and unchagned)
     
    Private Sub updateButton_Click()
        Dim continue As Long
     
        Call PutUserForm1DataBackInWorksheet
        
        Sheets("Master_list").Activate
       continue = MsgBox("Would you like to update another record?", vbYesNo)
         If continue = vbYes Then
                currProvNum.SetFocus
            Else
            Unload UserForm1
      
        End If
    End Sub
    
    'The routine grabs the information from the userform and places them back in the stored cells held by the
    ' .Tag attribute.  Specific command explination blocks below.
    
    Sub PutUserForm1DataBackInWorksheet()
    
      Dim ws As Worksheet
      Set ws = Worksheets("Master_list")
        
      Dim sAddress As String
      Dim sValue As String
      
      ActiveSheet.Unprotect "Datagen123"
      
      'Get the Worksheet Cell Address
      'Get the value from the UserForm
      'Put the value in the Worksheet
      
      'currProvNum ComboBox
      sAddress = UserForm1.currProvNum.Tag
      sValue = Trim(UserForm1.currProvNum.text)
      ws.Range(sAddress).Value = sValue
      
      'facilityName
      sAddress = UserForm1.facilityName.Tag
      sValue = Trim(UserForm1.facilityName.text)
      ws.Range(sAddress).Value = sValue
      
      'congDistNum
      sAddress = UserForm1.congDistNum.Tag
      sValue = Trim(UserForm1.congDistNum.text)
      ws.Range(sAddress).Value = sValue
      
      'congDistName
      sAddress = UserForm1.congDistName.Tag
      sValue = Trim(UserForm1.congDistName.text)
      ws.Range(sAddress).Value = sValue
      
      'netSysIdNum
      sAddress = UserForm1.netSysIdNum.Tag
      sValue = Trim(UserForm1.netSysIdNum.text)
      ws.Range(sAddress).Value = sValue
      
      'netSysIdName
      sAddress = UserForm1.netSysIdName.Tag
      sValue = Trim(UserForm1.netSysIdName.text)
      ws.Range(sAddress).Value = sValue
      
      'netSysIdName
      sAddress = UserForm1.custGroupCodeNum.Tag
      sValue = Trim(UserForm1.custGroupCodeNum.text)
      ws.Range(sAddress).Value = sValue
      
      'custGroupCodeNum
      sAddress = UserForm1.custGroupCodeName.Tag
      sValue = Trim(UserForm1.custGroupCodeName.text)
      ws.Range(sAddress).Value = sValue
    
      'Open/Closed Status
      sAddress = UserForm1.OpenClosedCombo.Tag
      sValue = Trim(UserForm1.OpenClosedCombo.text)
      ws.Range(sAddress).Value = sValue
      
      'Get dynamic row and target it at Column AE to datestamp it
      sAddress = "Y" + temp
      sValue = DateTime.Now
      ws.Range(sAddress).Value = sValue
      
      'Get dyanic Row and target it at Column AF to allow for user notes
      sAddress = "Z" + temp
      sValue = Trim(UserForm1.notesText.text)
      ws.Range(sAddress).Value = sValue
      
      Set ws = Nothing
      
      Range("Q1").Select
      
      ActiveSheet.Protect "Datagen123", True, True
    
    End Sub

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Error 2110 - can't move focus

    Is the control you are trying to set focus on in a frame or on a page of a multipage?

    Is it enabled?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    08-27-2014
    Location
    Albany, NY
    MS-Off Ver
    Office 2010
    Posts
    91

    Re: Error 2110 - can't move focus

    As an aside, I did check the properties of the combobox and it shows as enabled. Could it be because the msgbox is active and the userform is not? Would currProvNum.SetFocus be trying to set the focus of a non-existant currProvNum on the MsgBox?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Error 2110 - can't move focus

    The message box isn't active when you try to set focus to the control, focus should have returned to the userform as soon as the user clicked Yes/No on the message box.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Runtime error 2110 - SetFocus on label not working
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-04-2014, 08:43 PM
  2. Scrolling in a textbox can move focus outside it?
    By madhg in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-07-2009, 12:57 PM
  3. Cant move focus to the control because (Error)
    By realniceguy5000 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-28-2009, 09:40 AM
  4. Move cell focus in VBA
    By VD in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-02-2006, 11:20 AM
  5. [SOLVED] setfocus sometimes gets error 2110
    By tmort in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-18-2005, 11:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1