Userform Textbox not responding to <Enter> key

zinzah

New Member
Joined
Mar 9, 2010
Messages
49
I have 2 different forms with multiple controls. The first form has textboxes that 'exit' when the enter key is pressed. The other form has textboxes, but they do not 'exit' on the enter key...Any ideas?

First form partial code: (tb_address and other textboxes all respond to the enter key by exiting)
Code:
Private Sub cbEndTime_Change()

cbEndTime.Value = Format(cbEndTime.Value, "h:mm AMPM")
cbEndTime.Value = IIf(cbEndTime.Value = "12:25 AM", "06:00", cbEndTime)
cbEndTime.Value = IIf(cbEndTime.Value = "12:05 AM", "12:00", cbEndTime)


LblPromoHours.Caption = "Est. Hours:"
LblPromoHours.Visible = True
LblEstHours.Caption = (DateDiff("n", cbStartTime.Value, cbEndTime.Value) / 60) * (DateDiff("d", DTPicker1, DTPicker2) + 1)
LblEstHours.Visible = True
txtSponsor.Visible = True
LblSponsor.Visible = True
txtSponsor.SetFocus

End Sub

Private Sub txtSponsor_Enter()
cbEndTime.Locked = True
If frmAgent.tb_AgtNo <> "" Then txtSponsor.Value = frmAgent.tb_AgtNo & " - " & frmAgent.tb_AgentName
End Sub


Private Sub txtSponsor_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If AllowExit = True Then Exit Sub
If txtSponsor.Value = "" Then
    Cancel = True
    txtSponsor.SetFocus
    Exit Sub
End If

txtSponsor.Value = StrConv(txtSponsor.Value, vbProperCase)

tb_Address.Visible = True
lblAddress.Visible = True
tb_Address.SetFocus
End Sub

Private Sub tb_Address_Enter()
txtSponsor.Locked = True
If frmAgent.tb_AgtAddr <> "" Then tb_Address.Value = frmAgent.tb_AgtAddr
End Sub
The other form:tbNumofTypes does not respond to enter key:
Code:
Private Sub UserForm_Initialize()
cb_CouponType.RowSource = "Coupons"
tbNumofTypes.SetFocus

End Sub

Private Sub tbNumofTypes_Enter()
With tbNumofTypes
        .SelStart = 0
        .SelLength = Len(.Text)
    End With
End Sub


Private Sub tbNumofTypes_Change()
If TypeName(Me.ActiveControl) = "TextBox" Then
        With Me.ActiveControl
            If Not IsNumeric(.Value) And .Value <> vbNullString Then
                MsgBox "Sorry, only numbers allowed"
                .Value = vbNullString
            End If
        End With
    End If
End Sub
Private Sub tbNumofTypes_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If AllowExit = True Then Exit Sub
If tbNumofTypes.Value = "" Or tbNumofTypes.Value = 0 Then
Cancel = True
tbNumofTypes.SetFocus
Exit Sub
End If
lblCouponType.Visible = True
cb_CouponType.Visible = True
cb_CouponType.SetFocus
End Sub
Private Sub cb_CouponType_Enter()
tbNumofTypes.Locked = True

End Sub
All the textbox properties are the same for the textboxes in question...

TIA!
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,214,927
Messages
6,122,311
Members
449,080
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top