2017-07-27 157 views
0

我有一個帶有SQL表和過程的Access前端。我試圖找出最好的方法來獲得一個消息框,告訴用戶有多少記錄是通過SQL過程添加的。減去VBA變量

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 

我得到的結果是記錄,而不是我開始與記錄編號和記錄編號我之間的差額總數以...結束。 謝謝大家的幫助。

+2

在第二子,你永遠不會默認初始化'Rec1'so它是0,所以你總是在做'REC2 - 0'。 – litelite

+0

爲什麼不只是'AddReconciliationRecords'告訴你它插入了多少記錄? – litelite

+0

沒關係,我在發帖後5分鐘就想出了答案,我一直在努力研究如何獲得附加記錄的記錄數。 – Matt

回答

0

是的,我不得不把它們放在同一個小組,它的工作。對不起,我是新手。

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." 

末次