我有一个带有SQL表和过程的Access前端。我试图弄清楚我们最好得到一个消息框告诉用户通过SQL过程添加了多少记录。
Private Sub cmdAddReconciliationRecords_Click()
reccount1
AddReconciliationRecords
Reccount2
End Sub
Public Sub reccount1()
Dim db As DAO.Database
Dim Rec1 As Integer
Set db = CurrentDb
Rec1 = DCount("*", "dbo_reconciliation")
msgBox Rec1 & "Records" 'I will take this out once I get it to work
End Sub
'然后,过程AddReconciliationRecords运行附加记录
Public Sub Reccount2()
Dim db As DAO.Database
Dim Rec1 As Integer
Dim rec2 As Integer
Dim tot As Integer
Set db = CurrentDb
rec2 = DCount("*", "dbo_reconciliation")
tot = rec2 - Rec1
msgBox tot & " records added."
End Sub
我得到的结果是记录的总数,而不是我开始的记录号和我结束的记录号之间的差异。 感谢大家的帮助。
答案 0 :(得分:0)
是的,我必须将它们放在同一个Sub中并且它有效。对不起,我是这个人的新手。
Private Sub AddReconciliationRecords()
Dim oConnStr As String
Dim oConn As ADODB.Connection
Dim cmd As ADODB.Command
Dim recSet As ADODB.Recordset
Dim recSetStr As String
Dim db As DAO.Database
Dim Rec1 As Integer
Dim Rec2 As Integer
Dim Tot As Integer
Set db = CurrentDb
Rec1 = DCount("*", "dbo_reconciliation")
msgBox Rec1 & "Records"
'*****blocking server info
Set oConn = CreateObject("ADODB.Connection")
oConn.Open oConnStr
Set cmd = New ADODB.Command
cmd.ActiveConnection = oConn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "AddReconciliationRecords"
cmd.CommandTimeout = 300
cmd.Execute
oConn.Close
Rec2 = DCount("*", "dbo_reconciliation")
Tot = Rec2 + -Rec1
msgBox Tot & " records added."
End Sub