在鼠标按下功能需要刷新

时间:2014-11-08 13:33:36

标签: access-vba ms-access-2010

我想知道为什么在点击是/否框时生成的以下代码在第一次执行时不起作用。单击它后,代码将被执行,但不会确认已选中复选框,而是选中复选框但不是正确的结果。取消选择后,将获得正确的结果,然后再次选择时,代码将正确执行。

Private Sub cmdAccounting_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Me.cmdAccounting = 0 Then

    Me![frmMasterListOfEventsDetailHistory].Form!cost.Visible = True
    Me![frmMasterListOfEventsDetailHistory].Form!Etichetta35.Visible = True
    Me![frmMasterListOfEventsDetailHistory].Form!Etichetta37.Visible = True
    Me![frmMasterListOfEventsDetailHistory].Form!Etichetta43.Visible = True
    Me![frmMasterListOfEventsDetailHistory].Form!qty.Visible = True
    Me![frmMasterListOfEventsDetailHistory].Form!tot.Visible = True
    Me![frmMasterListOfEventsDetailHistory].Form!lineaAccounting1.Visible = True
    Me![frmMasterListOfEventsDetailHistory].Form!lineaAccounting2.Visible = True
    Me![frmMasterListOfEventsDetailHistory].Form!FileSaved.Visible = False
    Me![frmMasterListOfEventsDetailHistory].Form!lblFileSaved.Visible = False
    Me![frmMasterListOfEventsDetailHistory].Form!Favourite.Visible = False
    Me![frmMasterListOfEventsDetailHistory].Form!lblFavourite.Visible = False
    Me![frmMasterListOfEventsDetailHistory].Form!ln01.Visible = False
    Me![frmMasterListOfEventsDetailHistory].Form!ln02.Visible = False
    Me![frmMasterListOfEventsDetailHistory].Form!ln03.Visible = False
    Me![frmMasterListOfEventsDetailHistory].Form!ln04.Visible = False
    Me![frmMasterListOfEventsDetailHistory].Form!txtInfo.Visible = False
    Me![frmMasterListOfEventsDetailHistory].Form!ln05.Visible = False
    Me![frmMasterListOfEventsDetailHistory].Form!ln06.Visible = False

Else
    Me![frmMasterListOfEventsDetailHistory].Form!cost.Visible = False
    Me![frmMasterListOfEventsDetailHistory].Form!Etichetta35.Visible = False
    Me![frmMasterListOfEventsDetailHistory].Form!Etichetta37.Visible = False
    Me![frmMasterListOfEventsDetailHistory].Form!Etichetta43.Visible = False
    Me![frmMasterListOfEventsDetailHistory].Form!qty.Visible = False
    Me![frmMasterListOfEventsDetailHistory].Form!tot.Visible = False
    Me![frmMasterListOfEventsDetailHistory].Form!lineaAccounting1.Visible = False
    Me![frmMasterListOfEventsDetailHistory].Form!lineaAccounting2.Visible = False

    Me![frmMasterListOfEventsDetailHistory].Form!FileSaved.Visible = True
    Me![frmMasterListOfEventsDetailHistory].Form!lblFileSaved.Visible = True
    Me![frmMasterListOfEventsDetailHistory].Form!Favourite.Visible = True
    Me![frmMasterListOfEventsDetailHistory].Form!lblFavourite.Visible = True
    Me![frmMasterListOfEventsDetailHistory].Form!ln01.Visible = True
    Me![frmMasterListOfEventsDetailHistory].Form!ln02.Visible = True
    Me![frmMasterListOfEventsDetailHistory].Form!ln03.Visible = True
    Me![frmMasterListOfEventsDetailHistory].Form!ln04.Visible = True
    Me![frmMasterListOfEventsDetailHistory].Form!txtInfo.Visible = True
    Me![frmMasterListOfEventsDetailHistory].Form!ln05.Visible = True
    Me![frmMasterListOfEventsDetailHistory].Form!ln06.Visible = True

End If

Me.Form.Refresh
End Sub

1 个答案:

答案 0 :(得分:1)

您不必刷新,必须使用Clik事件,而不是MouseDown

 Private Sub cmdAccounting_Click()
   If Me.cmdAccounting = 0 Then
     Me![frmMasterListOfEventsDetailHistory].Form!cost.Visible = True
   Else
     Me![frmMasterListOfEventsDetailHistory].Form!cost.Visible = False
   End If
 End Sub

你的问题: MouseDown事件后,复选框的状态发生了变化, 所以你的结果是错的, 你必须使用refresh才能看到好结果......