Results 1 to 4 of 4

Cursor not showing in userform textbox

This is a discussion on Cursor not showing in userform textbox within the Excel Questions forums, part of the Question Forums category; Hi all, Newbie to Excel 2007, and first time here. My problem is that in a userform I have SetFocus ...

  1. #1
    New Member
    Join Date
    Dec 2010
    Posts
    15

    Default Cursor not showing in userform textbox

    Hi all,

    Newbie to Excel 2007, and first time here.

    My problem is that in a userform I have SetFocus to a specific textbox (txtGlucose) on opening, and also to any textbox(es) if no data was entered. Unfortunately, the text cursor doesn't appear, anywhere.

    Any ideas?
    Any help would be greatly appreciated.

    Code:
     
    Option Explicit
    Dim ws As Worksheet
     
    Private Sub cmdAdd_Click()
        Dim lRow As Long
        Dim MyStr
        MyStr = Time()
        'find  first empty row in database
        lRow = ActiveCell.Row
        'check for Blood Glucose Data
        If Trim(Me.txtGlucose.Value) = "" Then
            Me.txtGlucose.SetFocus
            MsgBox "Please enter Blood Glucose"
            Exit Sub
        End If
        'check for Insulin Injection Site Data
        If Trim(Me.cboLocation.Value) = "" Then
            Me.cboLocation.SetFocus
            MsgBox "Please enter Injection Site Location"
            Exit Sub
        End If
        'copy the data to the database
        Cells(lRow, 1).Value = Me.txtDate.Value
        Cells(lRow, 2).Value = Me.txtTim.Value
        Cells(lRow, 3).Value = Me.txtGlucose.Value
        Cells(lRow, 5).Value = Me.cboIns.Value
        Cells(lRow, 6).Value = Me.cboLocation.Value
        Cells(lRow, 7).Value = Me.txtNotes.Value
     
        'clear the data
        With Me
            .cboIns.Value = 37
            .cboLocation.Value = ""
            .txtDate.Value = Format(Date, "Medium Date")
            .txtNotes.Value = ""
            .txtTim.Value = MyStr
            .txtGlucose.Value = ""
            .txtDate.SetFocus
        End With
    End Sub
     
    Private Sub UserForm_Initialize()
        Dim cPart As Range
        Dim cLoc As Range
        Dim MyStr
        MyStr = Time()
     
        Set ws = Worksheets("LookupLists")
        With Me
            .cboLocation.List = Range("location").Value
            .cboIns.List = Range("insulin").Value
            .txtDate.Value = Format(Date, "Medium Date")
            .txtTim.Value = MyStr
            .txtNotes.Value = ""
            .cboIns.Value = 37
           ' .txtGlucose.SetFocus
        End With
        Me.txtGlucose.SetFocus
    End Sub
     
     Private Sub cmdClose_Click()
        Unload Me
    End Sub

  2. #2
    Board Regular
    Join Date
    Mar 2009
    Location
    Ohio USA
    Posts
    88

    Default Re: Cursor not showing in userform textbox

    Try this (untested)
    Code:
    Private Sub UserForm_Activate()
        Me.txtGlucose.SetFocus
    End Sub
    Remove the line of code from the Initialize Event.

  3. #3
    Board Regular Norie's Avatar
    Join Date
    Apr 2004
    Location
    Stirling
    Posts
    66,050

    Default Re: Cursor not showing in userform textbox

    Instead of using SetFocus why not try changing the Tab Order of the controls on the form?

    Right click the form and select Tab Order and you should be able to put the glucose textbox right at the top, then it will have focus when the forms opens.

    Also if you want to clear the form without keeping any of the data that's been entered just close it and open it again.
    Code:
    Unload Me
     
    UserForm1.Show ' change UserForm1 to name of form
    If posting code please use code tags.

  4. #4
    New Member
    Join Date
    Dec 2010
    Posts
    15

    Default Re: Cursor not showing in userform textbox

    Hey Guys,

    Thanks for the replies and advice.

    The code by jaslake did the trick.

    Thanks again

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com