How to check the status of an access form 2003, modal or model?

For a project running Access 2003, I have a form that is usually installed modeless, but in some cases opens as acDialog and, therefore, modal.

Now this form should check whether the modal itself is or not to change its behavior when the button is clicked.

Me.Form.Modal

returns the property value specified in design mode, and not the current state.

I found a similar answer for VB that suggests using the GetWindowLong API call for "user", but that does not translate to VBA (Microsoft KnowledgeBase 77316), I am afraid: Access2003 cannot find the "user" file.

In short: Is there a reliable way to determine if the form itself is modal or non-modal from within this form?

TIA.

Edit: It seems I remember that Me.Form is actually equivalent only to me. As far as I remember, the Form property is standard, so if you omit it, it is assumed. No matter how Me.Modal and Me.Form.Modal pass false, regardless of how the form is opened.

+3
source share
5 answers

Figured out the API (hacked a bit like Access, I think some fun things with forms)

Put it in the module

Const GWL_EXSTYLE = (-20)
Const WS_EX_MDICHILD = &H40

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


Public Function IsModal(ByVal lHwnd As Long) As Boolean

Dim lWinstyle As Long

  lWinstyle = GetWindowLong(lHwnd, GWL_EXSTYLE)
  If (lWinstyle And WS_EX_MDICHILD) Then
    IsModal = False
  Else
    IsModal = True
  End If

End Function

Then in your form_Load event (or anywhere)

  MsgBox "Hi I'm " & IIf(IsModal(me.Hwnd), "Modal", "Not Modal")
+3
source

, . , p122 , , , .

, p122 IsModal false. , IsModal true. , IsModal IsPopup.

+4

OpenArgs, , acDialog.

+1

( ), , acDialog + achidden, , set.Visible = True. , , , , . , . , , acDialog OpenForm:

  DoCmd.OpenForm "dlgMyDialog", , , , , acDialog +acHidden 
  With Forms!dlgMyDialog
    !cmbMyComboBox.Rowsource = ...
    !cmdClose.Tag = "Modal"
    .Visible = True ' <= code pauses here
  End With

, , ( acDialog) , acDialog. , acDialog + acHidden OnOpen .Visible = True ( , ) .Visible = False. , .Visible = True OnClose event.

, . , , , ( , ). , .

0

'screen.activeForm' 'Me' . , ,

(1)

(2) VBA

:

? screen.activeForm.modal<Enter>
<Answer>True

screen.activeForm.modal = False<Enter>

? screen.activeForm.modal<Enter>
<Answer>False
-1

Source: https://habr.com/ru/post/1717350/


All Articles