Userform control vanishes after clicking it

I have been trying to enhance Andy Pope's excellent code for anchoring controls on a resizable Excel userform. I have added four controls: two on the left side to contract and expand the form during runtime, and two on the right to simulate minimize and maximize. It's working so far except that when I click the maximize control, that control disappears until I click the resize control in the lower right corner and move (resize) it just a little. I've steeped through all the code I can to see if I can find where the control vanishes and what I can do about it, but to no avail. Can anyone help?

I've attached the Excel file. The original file and code came from http://www.andypope.info/vba/Anchor.htm.
AnchorControls--TEST-1-.xls
marrick13Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aikimarkCommented:
Haven't looked at the code, but I've encountered similar problems in the past.  Not all events trigger the form_resize event.  Sometimes, the resize event is triggered in the wrong order.

In one case, I made my own controls and menus that emulated the min/max/restore actions.
In another case, I added a timer to the form that inspected the state/size of the window and compared it to the state/size encountered in the prior timing event.
Martin LissOlder than dirtCommented:
The problem is that this line in imgMax_Click

     
FAnchorDemo.imgMax.Left = 576

Open in new window


is moving the control off-screen and for now you should comment it out.

When you add the code that maximizes the form when imgMax is clicked you'll need to add code like the following from the m_UpdateControls sub of the CAnchors class. That's the code that's being executed when you drag the resize handle at the bottom right.

 
 sngLeft = m_frmParent.InsideWidth - (OrigWidth - clsAnchor.OrigLeft - clsAnchor.OrigWidth) - clsAnchor.OrigWidth
                If sngLeft < clsAnchor.MinimumLeft Then sngLeft = clsAnchor.MinimumLeft
                If sngLeft < 0 Then sngLeft = 0
                cntTemp.Left = sngLeft

Open in new window


For your future debugging you may want to look at my debugging article.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
marrick13Author Commented:
Martin,
Thank you - commenting out the "FAnchorDemo.imgMax.Left = 576" did the trick (it was leftover from another userform I was using in Word). But I don't understand about adding the sngLeft = m_frmParent code to the imgMax click code. I did just add it and get a runtime 91 error (Object variable or With Block Variable not set"). I put this code in the imgMax click module and attached the revised code - can you advise what this code will do and why it produces the runtime error?
Martin LissOlder than dirtCommented:
Note that I said '"...you'll need to add code like the following..." and not "the same as".  That code moves the control relative to the form's size and you would need something like it. Here is code modified with code like the resize code. I determined the Const values (lines 20 to 22) by placing a breakpoint in the m_UpdateControls code and dragging the resize handle.

The new code is in lines 17 to 26.
Private Sub imgMax_Click() 'Maximize after resize

Dim formHeight As Long, formWidth As Long, formTop As Long, formLeft As Long
Dim TitleBoxLeft As Variant
Dim Multitest As Integer

'Me.cmbHghtReduc.Visible = True

On Error Resume Next
Unload Me
On Error GoTo 0

'Unload Me 'Unload form to clear memory (unloading here rather than just before the show command eliminates all screen flicker)

'Maximizes FAnchorDemo userform
'new
'FAnchorDemo.Height = FAnchorDemo.frmHgt.Caption
'FAnchorDemo.Width = FAnchorDemo.frmWidth.Caption
Dim sngLeft As Single
Const OrigWidth = 210
Const OrigLeft = 66
Const MinimumLeft = 200
' For testing just double the size of the form
FAnchorDemo.Height = FAnchorDemo.frmHgt.Caption * 2
FAnchorDemo.Width = FAnchorDemo.frmWidth.Caption * 2
imgMax.Left = FAnchorDemo.InsideWidth - (OrigWidth - OrigLeft - OrigWidth) - OrigWidth

FAnchorDemo.StartUpPosition = 0
'cmbHghtReduc.Value = "100%"

'++++++++++
'minLeft = 0.4
'MinWidth = 0.28
'minTop = 0.65
'MinHeight = 0.05574

'    txtTitle.Top = 6
'    txtTitle.Left = 258
'new
     'FAnchorDemo.imgMax.Left = 576
     
 '    FAnchorDemo.imgMin.Visible = True
'     FAnchorDemo.Left = 500
FAnchorDemo.Left = (lngHor * 0.5)
'    FAnchorDemo.Left = (lngHor * MinWidth) / 7.5
'    FAnchorDemo.Width = formWidthDef
'    FAnchorDemo.Top = (lngVert * (MinHeight) * 1.35)
'    FAnchorDemo.Height = formHeightDef

Load FAnchorDemo
FAnchorDemo.Show 'Reshow form as maximized version

End Sub

Open in new window

marrick13Author Commented:
Martin,

Thanks so much - I got the "you'll need to add code like the following" but don;t know VBA well enough (especially this resize code) to be able to take your suggestion and run with it. I've incorporated your code and it seems to work well. So thanks again!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.