Textbox defaults

C

Confused

I have a userform with 3 textboxes and a commandbutton
that acts as an enter botton. Textbox1 is for a target and
textboxes2 & 3 are for plus and minus tolerances. I am
working under the assumption that the tolerances are
balanced would like textbox3 to default to the textbox 2
value as soon as it is activated. Is this possible?
 
D

Dave Peterson

Maybe something like:

Option Explicit
Dim blkProc As Boolean
Private Sub TextBox3_Change()
If blkProc Then Exit Sub
'any code you have here
End Sub

Private Sub TextBox3_Enter()
If Me.TextBox2.Value <> "" _
And Me.TextBox3.Value = "" Then
blkProc = True
Me.TextBox3.Value = Me.TextBox2.Value
blkProc = False
End If
End Sub

The blkProc stuff acts like application.enableevents. Since we're changing the
value of textbox3 in code, we probably don't want the textbox3_change sub to
fire.

If you didn't have any textbox3_change code, you could dump the whole blkproc
stuff.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top