MS Access Query : Check if form is open / Check if parameter requires input

谁都会走 提交于 2019-12-11 04:47:37

问题


I'm currently trying, in a MS Access Query (using the GUI tool, and not the SQL tool), to check if a specific form is open or not, without using VBA.

Using the following expression :

Expr1 : [Formulaires]![Form1].[Visible]

If Form1 is open, the query works fine, but if Form1 is closed, it asks for input, since the Form1 isn't open, and the variable doesn't exist anymore.

Is there a way to check if a specific form is open, or to check if a certain variable requires input ?


回答1:


You would need a VBA function to discover this but you could call the function from your query and incorporate the result in your formula.

This function will return true if the form is loaded;

Function IsFormLoaded(strForm As String) As Boolean

Dim frm As Form

For Each frm In Forms
    If frm.Name = strForm Then
        IsFormLoaded = True
        Exit Function
    End If
Next

End Function

You can then use the function in an IIF statement;

IIF(IsFormLoaded('MyForm'), MyForm.Control.Value, '')



回答2:


Yes, use a function:

Public Function IsFormLoaded(ByVal strForm As String) As Boolean

    Dim frmForm     As Form
    Dim booLoaded   As Boolean

    For Each frmForm In Forms
        If frmForm.Name = strForm Then
            booLoaded = True
            Exit For
        End If
    Next

    IsFormLoaded = booLoaded

    Set frmForm = Nothing

End Function


来源:https://stackoverflow.com/questions/41058529/ms-access-query-check-if-form-is-open-check-if-parameter-requires-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!