Access 2003:无法获取命令按钮查询的结果显示在窗体上的文本框中

时间:2012-05-09 19:15:46

标签: ms-access ms-access-2003

我有一个命令按钮绑定到名为“GenderCount”的查询。单击按钮时,结果显示在子表中。我需要将结果显示在表单的文本框中(Text26)。这是我的代码 - 提前感谢任何建议:

Private Sub Command21_Click()
On Error GoTo Err_Command21_Click

    Dim stDocName As String

    stDocName = "GenderCount"
    DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Command21_Click:
    Exit Sub

Err_Command21_Click:
    MsgBox Err.Description
    Resume Exit_Command21_Click

End Sub

1 个答案:

答案 0 :(得分:0)

这就是你需要的

Private Sub Command21_Click()
On Error GoTo Err_Command21_Click

    me.txtField1 = dlookup("CountOfGender","GenderCount","Gender = M")
    me.txtField1 = dlookup("CountOfGender","GenderCount","Gender = F")

Exit_Command21_Click:
    Exit Sub

Err_Command21_Click:
    MsgBox Err.Description
    Resume Exit_Command21_Click

End Sub