0

我在 MS Access 工作。我正在尝试根据用户的登录信息(由某些 vba 代码确定)打开一个不向用户显示某些记录集的表单。

使用下面的 DoCmd.OpenForm,窗体打开,但我希望对用户隐藏的记录集(其中 G_Var = YES)仅被过滤掉。所以用户可以删除过滤的数据表表单并查看行(我不想禁用过滤器)。我究竟做错了什么?

DoCmd.OpenForm "Metrics", acFormDS, , "G_Var = 'NO'"  

我也在想也许我可以编写某种查询来检索这些信息。也许是这样的:

rs.Open "Select * FROM Metrics WHERE G_Var = 'NO';", CurrentProject.Connection

我只是不明白我将如何获取这些查询信息并将其输出到表单中。通过定义记录源,我能够以这种方式完成任务:

Private Sub btnMetrics_From_Click()

  DoCmd.OpenForm "Metrics", acFormDS
  Forms.Item("Start Form").Visible = False

End Sub

Private Sub Form_Activate()
  Dim rs As New ADODB.Recordset
  Dim sql As String
  Dim Boo As Boolean

    g_User = UserInfo(ap_GetUserName())
    Boo = False

rs.Open "SELECT * FROM tbl_User_Info WHERE G_Var_Access = TRUE;", CurrentProject.Connection

Do Until rs.EOF = False
    If rs.Fields("User_Name").Value = g_User Then
        Boo = True

        Exit Do
    End If
Loop

rs.Close

If Boo = True Then

Else
    Me.RecordSource = "SELECT * FROM Metrics WHERE G_Var = 'NO';"
End If

    Me.Requery

End Sub

谢谢

4

1 回答 1

1

您可以尝试这样的事情作为您的主要 RecordSource SQL ...

SELECT M.*
FROM Metrics AS M,tbl_User_Info AS U
WHERE U.User_Name=CurrentUser()
AND M.G_Var LIKE IIF(U.G_Var_Access=TRUE,'*','NO')
于 2013-08-05T19:38:29.700 回答