PDA

View Full Version : Solved: Highlight Text in TexBox on UserForm Open



Darren
09-13-2007, 03:16 AM
Hi Captains

I have searched the KB but not yet found something to help with this small problem.

I have a Userform called BasicTerms on this user form i have a TextBox Called txtTurnoverIncl

When this user form opens or activated whatever number is in txtTurnoverIncl Texbox must be highlighted in blue.

I have tried to SetFocus and that just selects the correct box but the cursor is next to the 1 and the number is not highlighted i will post my code for this userform

Option Explicit
Private Sub UserForm_Activate()
TextBox1 = 1#
TextBox2 = 0#
txtTurnoverIncl.SetFocus
End Sub
Private Sub UserForm_Initialize()
Dim i As Long
For i = 0 To 35
cmbRoyalty.AddItem Format(i / 100, "0%")
Next i

TextBox1.Value = 1#
txtTurnoverIncl = TextBox1
TextBox2.Value = 0
cmbRoyalty.Text = TextBox2
txtTurnoverIncl.SetFocus

End Sub
Private Sub txtTurnoverExcl_Change()
If txtRoyalty.Text <> "" Then

lblRoyaltcost.Caption = Format(CDbl(txtTurnoverExcl.Text) * _
CDbl(txtRoyalty.Text) / 100, "#,##0.00")
End If

End Sub

Private Sub txtRoyalty_Change()
If txtTurnoverExcl.Text <> "" Then

lblRoyaltcost.Caption = Format(CDbl(txtTurnoverExcl.Text) * _
CDbl(txtRoyalty.Text) / 100, "#,##0.00")
End If
End Sub
Private Sub cmbRoyalty_Change()

If lblTurnoverExcl.Caption <> "" Then
If cmbRoyalty.Value <> "" Then

lblRoyaltcost.Caption = Format(CDbl(lblTurnoverExcl.Caption) * _
Replace(cmbRoyalty.Value, "%", "") / 100, "#,##0.00")
End If
End If
End Sub

Private Sub CommandButton10_Click()
Hide
Intro.Show
End Sub
Private Sub CommandButton8_Click()
Hide
NewVenture.Show
txtTurnoverIncl.SetFocus
End Sub
Private Sub CommandButton9_Click()
Hide
StockTake.Show
End Sub
Private Sub Label16_Click()
End Sub
Private Sub Label24_Click()
End Sub
Private Sub txtTurnoverIncl_Exit(ByVal Cancel As MSForms.ReturnBoolean)

End Sub
Private Sub CommandButton1_Click()
Hide
OverHeads.TextBox14.Text = BasicTerms.lblTurnoverExcl.Caption
OverHeads.Show
End Sub
Private Sub CommandButton2_Click()
Hide
HelpFile1.Show
End Sub
Private Sub CommandButton3_Click()
Hide
SalesTaxCalc.Show
End Sub
Private Sub CommandButton4_Click()
Hide
PromoCalc.Show
End Sub
Private Sub CommandButton5_Click()
Me.PrintForm
End Sub
Private Sub CommandButton6_Click()
Hide
HelpFile2.Show
End Sub
Private Sub CommandButton7_Click()
Hide
DailyControl.Show
End Sub
Private Sub txtTurnoverIncl_AfterUpdate()

With txtTurnoverIncl
.Text = Format(.Text, "#,0")

End With


End Sub
Private Sub txtTurnoverIncl_Change()
With txtTurnoverIncl
If .Text = "" Then
lblT.Caption = ""
Else
lblT.Caption = Format(Round(.Text * 14 / 114, 2), "#,##0.00")
lblTurnoverExcl.Caption = Format(CDbl(.Text - .Text * 14 / 114), "#,##0.00")
End If


End With

End Sub
Private Sub TextBox1_Change()
TextBox1 = Format(TextBox1, "#,0")

End Sub

I hope you can help solve this last problem

Darren
South Africa

Image Current is what it looks like on open
And BG image is after i have highlighted it myself this is the what the result should be on open

rory
09-13-2007, 03:26 AM
Try:
Private Sub UserForm_Activate()
With Me.txtTurnoverIncl
.SelStart = 0
.SelLength = Len(Me.txtTurnoverIncl)
End With
End Sub

Darren
09-13-2007, 03:32 AM
Hi rory

Thanks so much it works like a dream:friends:

Darren