Hi NG; I have a couple of UserForm witin my VBA-project. All of these forms have a Cancel-button to allow the user to Cancel and hide the userform and return to ACAD. This button works fine. Each userform has a Cross in the upper-right corner and the user has the possibility to Cancel the form this way. The only problem is what is returned when using that button. Is it poosible to catch if the user has canceld it that way? ---5 minutes later after trying some more--- I did manage to solve this using the Terminate-event. But is there another way to do it? TIA David
Here are a couple of subs I use to remove the titlebar altogether or just disable the close cross & right clicking the titlebar and selecting close. Call the appropriate one from the userform Activate event. Watch out for wordwrap on the declare functions. ********************** Option Explicit Private Declare Function GetActiveWindow Lib "user32" () As Long Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal uPosition As Long, ByVal uFlags As Long) As Long Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public Sub DisableClose() Dim hwnd As Long Dim hMenu As Long hwnd = GetActiveWindow() hMenu = GetSystemMenu(hwnd, 0) Call RemoveMenu(hMenu, 6, &H400) Call RemoveMenu(hMenu, 5, &H400) Call DrawMenuBar(hwnd) End Sub Public Sub Remove() Dim hwnd As Long Dim dwNewLong As Long hwnd = GetActiveWindow() dwNewLong = GetWindowLong(hwnd, -16) dwNewLong = dwNewLong And Not &HC00000 Call SetWindowLong(hwnd, -16, dwNewLong) DrawMenuBar hwnd End Sub ********************** Regards - Nathan
Hi David. You try do is the following thing: The code of button Cancel you copy it and paste in the Terminate event of the Form. Private Sub UserForm_Terminate() ...equal code to button Cancel... End Sub Un saludo de SpeedCAD... CHILE FORO: http://www.hispacad.com/foro