我可以跟踪两次单击按钮之间的时间并将其以及表单上的其他一些条目保存为使用 VBA 的 Access 中的新记录吗?

问题描述

我正在尝试在 Access 2007 - 2013 中创建一个表单,该表单将跟踪两次单击按钮之间的时间。第一次单击时,按钮的标题将从“开始”变为“停止”,第二次单击时将变为“开始”。我这样做是通过声明

Public timeTrial as Boolean

并使用以下代码启动点击事件:

Private Sub cb_Start_Click()  
Dim Ops,Qty,Comments,Dte,StartTime,EndTime,totalTime As String  

Dte = Format(Date,"mm/dd/yyyy")
Ops = cb_Ops.Value
Qty = tb_Qty.Value
Comments = tb_Comments.Value

If timeTrial = False Then  
    timeTrial = True  
    cb_Start.Caption = "Stop"  
    StartTime = Time  
Else 
    timeTrial = False  
    EndTime = Time  
    cb_Start.Caption = "Start"  
End If

'Saving the record using DoCmd
DoCmd.Runsql INSERT INTO [Log] (Dte,Ops,Comments) VALUES('" & Dte & "','" & Ops & "','" & StartTime & "','" & EndTime & "','" & Qty & "','" & Comments & "')"

我面临的问题是,即使按钮更改了标题,每次单击该按钮时都会输入一条新记录,为同一交易提供两条记录。

非常感谢任何指针。

谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)