View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Stephen Knapp Stephen Knapp is offline
external usenet poster
 
Posts: 34
Default TextBox on a UserForm -- AfterUpdate

Fred:

From my first look, it appears that your code is correct. I assume that
the text box in question shows up on the screen and behaves correctly, except
for the responding to the event. Where is the "Sub txtZoom_AfterUpdate()"
code located? It has to be inside of the code module (actually, the form's
class module) so that it can be recognized for the event. If you have it in
a separate module, then Excel can't find it to execute. If it is in the
class module, I'd place a few DEBUG.PRINT or MSGBOX statements in and around
the click event code to make sure that I'm where I want to be. Also, I'd
build a temporary button on the form to "manually" activate (simulate) the
AfterUpdate event just to make sure that everything is working as planned.

Steve in Ohio

"Fred Holmes" wrote:

I'm trying to get the AfterUpdate event to work in a TextBox on a
UserForm. It works fine if the TextBox is created using the Controls
Toolbox and placing the TextBox on the form in the "conventinal"
manner. However, I'm trying to use a TextBox that is created with a
Set statemnt in the UserForm code.

Dim WithEvents txtZoom As MSForms.TextBox

Set txtZoom = Me.Controls.Add("forms.TextBox.1", "txtZoom", True)
With txtZoom
.Visible = True
.Top = 3
.Left = 50
.Height = 18
.Width = 40
.Text = "100"
.TextAlign = fmTextAlignCenter
.BackStyle = fmBackStyleOpaque
.BackColor = &H80000005 ' White
.BorderStyle = fmBorderStyleSingle
.BorderColor = &H80000006 ' black
.SpecialEffect = fmSpecialEffectSunken
.Font.Size = 10
.Font.Bold = True
.EnterFieldBehavior = fmEnterFieldBehaviorSelectAll
.EnterKeyBehavior = False
.HideSelection = True
.SelectionMargin = True
.TabKeyBehavior = False
.IMEMode = fmIMEModeNoControl

End With

Private Sub txtZoom_AfterUpdate() ' AfterUpdate, not Change
' This sholud execute the zoom function by pressing Enter
' This works fine on the Old Form, but not on the New Form
' in which all of the controls are created by Set statements
' in Code. AfterUpdate does not "fire" on the new Form.
Me.Zoom = txtZoom.Text
Me.Height = hf * (txtZoom.Text / 100) ' hf = initial form height
Me.Width = wf * (txtZoom.Text / 100) ' wf = initial form width
End Sub ' Private Sub txtZoom_AfterUpdate()

The properties listed in the code for txtZoom are those taken from the
Properties dialog of the verision in which the controls are created on
the form in the "customary" fashion. I tried to make sure that any
property that looked at all "relevant" was set to an identical value
in both instances.

MS Office 2003, SP-1 WinXP, SP-2

Thanks for any help.

Fred Holmes