×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Disable X button on forms (VBA)
2

Disable X button on forms (VBA)

Disable X button on forms (VBA)

(OP)
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

RE: Disable X button on forms (VBA)

Have you tried this yet?

http://www.vbforums.com/showthread.php?t=363931

I don't think it's going to be possible without using the Windows API as in the example there.

BTW, this is the first link when you google the subject line of your post.....

-handleman, CSWP (The new, easy test)

RE: Disable X button on forms (VBA)

(OP)
Yeah, I was trying to work with that solution, but it's not working about for me.  I guess I don't know enough to implement it.  I wasn't working for me.  this is the same solution that can be found on 10 sites I found.   

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

RE: Disable X button on forms (VBA)

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...

RE: Disable X button on forms (VBA)

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)

RE: Disable X button on forms (VBA)

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources