+ Reply to Thread
Results 1 to 6 of 6

Excel 2007 : Help with setting focus

  1. #1
    Registered User
    Join Date
    12-24-2010
    Location
    Ohio
    MS-Off Ver
    Excel 2007
    Posts
    89

    Help with setting focus

    Hi all,

    I'm a newbie to Excel, so please be patient with me.

    The attached file has a user form that I cannot get the SetFocus to work. The cursor should appear in the glucose field when the form is opened.

    The other thing I cannot figure out is this. The user form adds records by finding the first empty row in the database, but since I made the userform Modeless, I would like to add the record to a row I click on with the mouse.

    Because the sheet for the printout is formated with empty rows after a group of seven records, see the sheet titled 'BlankForm', I thought it would be easier to just click on the row where I would like the record to be placed rather than in a straight database, and then transfer to the BlankForm for a printout. Which I have Nooooooo idea on how to do.

    The original coding is not mine. I found the code somewhere and after trial and error got it to work, somewhat, for my needs.

    Any help on the setting of the focus would be greatly appreciated.

    George
    Attached Files Attached Files

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Help with setting focus

    Your code sets focus to txtDate, not txtGlucose. See this amended code. Also, I have created two Named Ranges to populate the Comboboxes using the List Property instead of looping
    Please Login or Register  to view this content.
    Where are you planning to write the entries to?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    12-24-2010
    Location
    Ohio
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: Help with setting focus

    Hey royUK,

    Thanks for the reply and the revised code. Unfortunately it didn't seem to work. When I try to open the userform I get a run-time error '1004'; Method "Range" of object "_Global' failed

    I have absolutly no idea what that means.

    Looking at my code I see that I do have the focus set to txtGlucose, why it appears differently on the file I attached I have no idea unless I uploaded the file before I saved it with the change. Anyway the setfocus to txtGlucose still didn't work.

    The records are writen to the sheet 'GlucoseData'

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Help with setting focus

    I would think the error is occurring because you haven't created the Named Ranges.

    You haven't set the UserForm to Modal.

    See this amended example, select the row to make the entry to & the data will be posted there
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    12-24-2010
    Location
    Ohio
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: Help with setting focus

    royUK

    Thanks so much for the help. I need to study your code to see the diffence and why yours works.
    Hey, that how people learn.

    Again, thanks

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Help with setting focus

    You need to look at the sheet with the combobox lists in & see the named ranges that I have used. These are used to load the comboboxes more efficiently than looping through the cells.

+ 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