none
MsgBox positioning, outlook RRS feed

  • Question

  • I put a password on my outlook using a MsgBox, so when i run outlook then the MsgBox apears and asks for the password but the MsgBox "hides" behind the "Outlook 2010 starting" window.

    Can someone please help me to either move the MsgBox or to make it "Top Most" so that you can see it asking for a password.

    Here's my code if it might help:

    Private Sub Application_Startup()

    Dim sread As String

    sread = InputBox("Please insert password", "Password")

        If sread = "12344" Then

            Else

                MsgBox "Incorrect Password!!", vbCritical, "Error"

                Application.Quit

        End If

    End Sub

    Mr.SMP

    Friday, February 10, 2012 1:21 PM

Answers

  • Instead of what you're trying to do, why don't you just store your data in a password protected PST file? That way when you open Outlook is will request the password for the PST file and you don't have to do anything.
     
    To get the InputBox to be set TopMost you need to get its window handle and call SetWindowPos() with an argument of HWND_TOPMOST. However, that will prevent any other window from being used until that InputBox window is dismissed. You'd need to use FindWindow() to find a window with the class of "#32770" and the caption of whatever you title our InputBox. If you don't explicitly title it the caption would be "Microsoft Outlook".
     
    So your code declarations would be like this:
     
    Public Const HWND_TOPMOST = -1
    Public Const SWP_NOSIZE = &H1
    Public Const SWP_NOMOVE = &H2
    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName$, _
      ByVal lpWindowName$) As Long

    Public Declare Function SetWindowPos Lib "user32" _
      (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, _
      ByVal X As Long, ByVal y As Long, ByVal cx As Long, _
      ByVal cy As Long, ByVal wFlags As Long) As Long
     
    The code would for the window would look something like this:
     
    Dim hWnd As Long
    hWnd = FindWindow("#32770", "MyPasswordDialog") ' InputBox title
    If hWnd <> 0 Then
        Dim ret As Long
        ret = SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE + SWP_NOMOVE)
    End If

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Mr.SMP" <=?utf-8?B?TXIuU01Q?=> wrote in message news:e8b8fae7-6936-4451-abd2-9d44bf3cc2c7...

    I put a password on my outlook using a MsgBox, so when i run outlook then the MsgBox apears and asks for the password but the MsgBox "hides" behind the "Outlook 2010 starting" window.

    Can someone please help me to either move the MsgBox or to make it "Top Most" so that you can see it asking for a password.

    Here's my code if it might help:

    Private Sub Application_Startup()

    Dim sread As String

    sread = InputBox("Please insert password", "Password")

        If sread = "12344" Then

            Else

                MsgBox "Incorrect Password!!", vbCritical, "Error"

                Application.Quit

        End If

    End Sub

    Mr.SMP


    Ken Slovak MVP - Outlook
    Friday, February 10, 2012 4:28 PM
    Moderator