+ Reply to Thread
Results 1 to 4 of 4

Focus from listbox selection to textbox gives an error

  1. #1
    Registered User
    Join Date
    08-17-2012
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    85

    Focus from listbox selection to textbox gives an error

    I have a textbox3 for input value, and based on that value, if exist/correct focus is set on next textbox(12) if not listbox is populated with all values from a column (named range) and most similar value with that in textbox3 is selected in listbox.

    After correct value is selected listbox can not unfocus. Every attempt to focus to any other object results in this error (Run-time error -2147467259 (80004005) Unspecified error).

    And here is the code :

    Please Login or Register  to view this content.
    And

    Please Login or Register  to view this content.
    I've tried every combination that crossed my mind and everything resulted in same Unspecified error.
    Last edited by Jovica; 03-23-2014 at 05:54 PM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,652

    Re: Focus from listbox selection to textbox gives an error

    I don't see anything wrong with the code you've posted.

    Just to confirm, you do have a Textbox12 (not Textbox2) ?

    Do you have another procedure that sets ListBox1.SetFocus? Maybe there is a circular situation where one control's focus is set which in turn selects another control? Just a stab in the dark.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Focus from listbox selection to textbox gives an error

    Hi Jovica,

    I could not duplicate your problem using Excel 2003.

    I have two suggestions that have nothing to do with your problem:

    a. Use Option Explicit. To prevent typos from ruining days and weeks of work you need 'Option Explicit' at the top of each code module.
    This forces you to declare every variable.
    http://www.cpearson.com/excel/DeclaringVariables.aspx

    b. When you're done with the 'ws' (Worksheet) object, the object should be cleared:
    Please Login or Register  to view this content.
    See http://www.mrexcel.com/forum/excel-q...thing-why.html

    Lewis

  4. #4
    Registered User
    Join Date
    08-17-2012
    Location
    Serbia
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: Focus from listbox selection to textbox gives an error

    I had to do a userform all over again, which is always a best solution (not the quickest) then I compare those two. I had cancel = true in textbox2 event and that was the problem, I don't know know what would that affect listbox since listbox tab index was after textbox 3, strange?

    @ AlphaFrog I had to insert few textboxes in the middle of the form, that's why it's 12 after 3.
    @ LJMetzger Thank you. I always forget Option Explicit. Also didn't know about Set ws = Nothing.

    Once again thank you guys.

+ 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] UserForm - How To Make TextBox Value Change Depending On ListBox Selection
    By ScotyB in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-26-2013, 05:05 PM
  2. [SOLVED] Textbox focus
    By tradinup2 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-08-2013, 12:25 AM
  3. Multi select Listbox Items selection based on other Listbox item selection.
    By srinivassathi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-20-2011, 05:53 AM
  4. Textbox update with previous selection from listbox
    By Binsy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-29-2010, 05:03 PM
  5. [SOLVED] Retaining focus on a textbox / listbox item pair after validation = false.
    By chatterbox in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-04-2006, 06:50 AM

Tags for this Thread

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