Consulting

Results 1 to 6 of 6

Thread: Form showing odd sizes

  1. #1

    Exclamation Form showing odd sizes

    Hi Mates,

    I have used a code that allows me to remove the Xbutton in a form.

    But it seems that i need to resize my Form in VBA editor in order to show the size that i want.

    Transport Form.JPG<--- Resized from VBA editor

    Transport form 2.JPG<-- and when i try to run it it shows like this.

    Can someone help me out thanks in advance.
    Last edited by tramyer; 01-18-2018 at 01:56 AM.

  2. #2
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,158
    Location
    You may be better off deactivating the X button rather than removing it.

    This will also give you the opportunity to explain to the user why it is deactivated via use of a message box.

    Hope this helps
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved

    Excel 365, Version 2401, Build 17231.20084

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    The "Forms" shown on those two images are the same size on my screen.
    The top image does not have a command button.
    The bottom image does not have a Title Bar.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  4. #4
    Hi georiboy,

    I need to hide the xbutton so that. It will have a good looking msgbox. And sometimes it allows the user to just use the x box to close the msgbox. So to avoid that i need to remvoe the xbutton.

  5. #5
    Quote Originally Posted by SamT View Post
    The "Forms" shown on those two images are the same size on my screen.
    The top image does not have a command button.
    The bottom image does not have a Title Bar.
    Yes the code removes the title bar (xbutton). But in return i have to resize my form in VBA editor just to show the desired size i want. May the code adjuses the size of the form. Moving it downard so that the user will not be able to see the xbutton.

  6. #6
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,158
    Location
    Maybe try to hide only the x button and not the whole bar:

    Private Const GWL_STYLE = (-16)Private Const WS_SYSMENU = &H80000
    Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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
    Private Declare Function DrawMenuBar Lib "User32" (ByVal hWnd As Long) As Long
    
    
     Private Sub UserForm_Initialize()
     
        Dim FndForm, tpe
        
        FndForm = FindWindow(vbNullString, Me.Caption)
        
        If FndForm <> 0 Then
            tpe = GetWindowLong(FndForm, GWL_STYLE)
            tpe = SetWindowLong(FndForm, GWL_STYLE, tpe And Not WS_SYSMENU)
            DrawMenuBar FndForm
        End If
        
    End Sub
    Hope this helps
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved

    Excel 365, Version 2401, Build 17231.20084

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •