Results 1 to 9 of 9
  1. #1
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Determine Window State (Access 97 SR-1)

    I'm having a senior moment. <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35> If a form is opened using DoCmd.OpenForm with the WindowMode argument set to acDialog, how can I determine from within the form itself that it was opened as a dialog? The Popup and Modal properties return the saved settings for those properties, not the actual window mode of the form. Anyone?
    Charlotte

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Determine Window State (Access 97 SR-1)

    After consulting with my expert, we concluded the only way to do that is to put a flag on the form and set it to indicate the mode of the window. We had another person with a very similar issue, and couldn't find any other way of doing it.
    Wendell

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Determine Window State (Access 97 SR-1)

    Thanks, Wendell. I had pretty much come to the same conclusion. Oh, well, that's what OpenArgs are for. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    Charlotte

  4. #4
    4 Star Lounger
    Join Date
    Aug 2002
    Location
    Dallas, Texas, USA
    Posts
    594
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determine Window State (Access 97 SR-1)

    Option Compare Database
    Option Explicit
    Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Property Get IAmADialogForm() As Boolean
    Dim strTemp As String
    Dim dwReturn As Long
    strTemp = Space(255)
    dwReturn = GetClassName(Me.hwnd, strTemp, 255)
    strTemp = Left(strTemp, dwReturn)
    IAmADialogForm = strTemp = "OFormPopup" & Chr(0)
    End Property
    Private Sub Form_Open(Cancel As Integer)
    If Me.IAmADialogForm Then
    MsgBox "Yes"
    Else
    MsgBox "No"
    End If
    End Sub

    Put that code in the code page of your form. (It's the entire page of the form I just wrote.....) As long as you have the Popup Property set to No, the IAmADialogForm property works fine. If Popup is Set to Yes, then that property indicates true all of the time.

    If you REALLY REALLY need to have this when a form is also designed as a popup, then I can look deeper into it for ya......

    "Never trust the experts....." <img src=/S/evilgrin.gif border=0 alt=evilgrin width=15 height=15>

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Determine Window State (Access 97 SR-1)

    Thanks, Drew. I figured I could do it with an API call, I just thought maybe I had missed something in Access itself that would tell me. I bypassed the form I needed this for, so it isn't urgent, but I'll add your code to my code library for the next time I have this bright idea. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Charlotte

  6. #6
    4 Star Lounger
    Join Date
    Aug 2002
    Location
    Dallas, Texas, USA
    Posts
    594
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determine Window State (Access 97 SR-1)

    Okay, just remember that it's only right 15 out of 16 scenarios. With all the combinations of the Popup Property, Modal Property and whether it's called up as dialog or not, when it's Popup, but not Modal, and is called normally, then it will be wrong...a false positive.

    (Of course it is only detecting that it's dialog too....not whether it's modal. The only time it is accurate there is when the Popup property is No.)

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Determine Window State (Access 97 SR-1)

    That's OK, Drew. None of the forms I would use it on would have their Modal and Popup properties set to Yes, so it would work consistently in that environment. Thanks again.
    Charlotte

  8. #8
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Determine Window State (Access 97 SR-1)

    I guess this is a non-issue now, but in event should become an issue, you could use the WIN API GetWindowLong function to test if form opened with acDialog flag set. I could not find a standard window style constant that represented this flag (of course Access forms are not same as "real" Windows forms) but you can test for this flag using value of &H70000 for bitwise comparison, so defined a constant for this value. Function declaration:

    Declare Function apiGetWindowLong Lib "user32" Alias "GetWindowLongA" _
    (ByVal hwnd As Long, ByVal nIndex As Long) As Long

    Public Const GWL_STYLE = (-16)
    Public Const WS_DIALOG As Long = &H70000

    Example of use in form Open event:

    Private Sub Form_Open(Cancel As Integer)

    Dim lngWS As Long

    DoCmd.Restore

    lngWS = apiGetWindowLong(Me.hwnd, GWL_STYLE)

    If lngWS And WS_DIALOG Then
    Me.Label1.Caption = "Form not opened with acDialog flag."
    Else
    Me.Label1.Caption = "Form opened with acDialog flag."
    End If

    End Sub

    When testing this worked OK with any combination of form properties (popup, modal, etc). Note however, if form defined as Modal, but opened w/o "acDialog" argument specified using DoCmd.OpenForm method, label caption will read "Not opened..."; the acDialog argument is apparently what sets the flag being tested here.

    HTH

  9. #9
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Determine Window State (Access 97 SR-1)

    Perfect, Mark! Thanks.
    Charlotte

Posting Permissions

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