+ Reply to Thread
Results 1 to 3 of 3

Problem with SetFocus

  1. #1
    Registered User
    Join Date
    11-20-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    29

    Problem with SetFocus

    Hey everyone!

    I am having a little trouble with an addition flash card userform that I am working on. Everything was working exactly as I intended until I tried to implement a keyup event. My intention was to remove the need to press return twice (once for entering answer in text box, and once again to proceed to the next question). Now, with the keyup event, I am able to enter the answer and go to the next question, however the focus is then placed on the "Next" command button. I have tried putting "me.txtSolution.SetFocus" throughout my code to no avail. Any thoughts would be greatly appreciated.

    Thank you for your help! This is what I have so far:

    Please Login or Register  to view this content.
    Last edited by exceln00b22; 05-25-2013 at 05:12 PM.

  2. #2
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Problem with SetFocus

    I'm certainly not an advanced userform developer, so I won't comment on the question you posed. However, after reviewing the code, I thought I would comment on your variable declarations. I'm not sure if you know this, but with VBA, you have to declare all variables as a type, otherwise they take the default variant type. It does not matter in this case, but getting in a good habit now could potentially save you a headache down the road.

    In your declarations, you have effectively declared:

    n1 as Variant (when I think your intention was Integer)
    n2 as Integer
    high as Variant (when I think your intention was Double)
    low as Double

    Something to look out for in the future. Good luck.
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Problem with SetFocus

    Duplicate post

    http://www.excelforum.com/excel-prog...tle-tweak.html
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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