Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable X button on forms (VBA) 2

Status
Not open for further replies.

fcsuper

Mechanical
Apr 20, 2006
2,204
0
0
US
I would ask this over at the VBA forum, but it looked kinda dead over there, so I'll ask here (since this is for a macro anyway).

Is there a simple method to disable the X button on a VBA form that will work within SW's VBA? On this macro Rigid Custom Properties, the X Button is taking an action that is causing some bizarre activity, so i just want to disable it. It's causing the deletion of the custom properties...I realize this may be do to sloppy coding by me, but in lieu of rewriting this macro, I would like to just disable the X button.

Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
 
Replies continue below

Recommended for you

Have you tried the form's QueryClose event?

It fires when the 'x' button is pressed. Setting 'Cancel' to something non-zero cancels the action.

Code:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)

   If CloseMode = vbFormControlMenu Then Cancel = 1

End Sub


Cheers...
 
Seems to work pretty well for me. The main thing you have to do is get rid of that "ThunderDFrame" string and replace it with a null string (vbNullString). The reason for this is the FindWindow function looks for a match in two places: the window class and the window title string. "ThunderDFrame" is the class name for a Microsoft Excel VBA user form. If you have any idea what the class name for a SW VBA user form is, you can use that. Otherwise, using vbNullString causes the function to look only at the title string. Since your title string is fairly unique, this probably won't be a problem.

-handleman, CSWP (The new, easy test)
 
 http://files.engineering.com/getfile.aspx?folder=77e65799-5fdf-40e4-a50d-b616ff686932&file=RigidCustomPropertiesV4.swp
Handleman,

Thanks. I just couldn't didn't figure out that part. I thought it was asking for the actual name of the form.

VanHunks,

Thanks for the reply. Playing with how the X button works didn't work too well for me, as there are functions that I sometimes want available even when the form is closed. Having the button available but not function is cool, but also a little annoying to the user. I'll be adding that code to my snipplets list though. :)

Matt Lorono
CAD Engineer/ECN Analyst
Silicon Valley, CA
Lorono's SolidWorks Resources
Co-moderator of Solidworks Yahoo! Group
and Mechnical.Engineering Yahoo! Group
 
Status
Not open for further replies.
Back
Top