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.
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