请看我全部代码如下:
Option Explicit
Private conn As ADODB.Connection
Private Rst As New ADODB.Recordset
Private Sub Command1_Click()
Dim i, j, b As Single
Dim a
If Not Rst.EOF() Then
For i = 1 To Rst.RecordCount
a = a + Val(Rst.Fields("j10").Value)
b = b + Val(Rst.Fields("d10").Value)
Rst.MoveNext
Next i
Text1.Text = Val(a)
Text2.Text = Val(b)
If Text1.Text <> Text2.Text Then
MsgBox "请检查会计凭证!"
End If
End If
End Sub
Private Sub Command2_Click()
Dim strsql As String
Dim i As Long
Dim Total As Long
Total = 0
For i = 1 To 9
strsql = "Select Sum(j" & i & ") from fl2 where z" & i & "='银行存款' GROUP BY Z" & i
If conn.Execute(strsql).EOF = False Then
Total = Total + conn.Execute(strsql)(0)
End If
Next
conn.Close
Set conn = Nothing
Text4.Text = Val(Total)
End Sub
Private Sub Form_Load()
Dim ConString As String
ConString = "Provider=Microsoft.Jet.OleDb.4.0;Persist Security Info = False;" _
& "Data Source =" & App.Path & "\db1.mdb;Jet OleDb:"
Set conn = CreateObject("ADODB.Connection")
With conn
.ConnectionString = ConString
.Open
End With
Rst.CursorLocation = adUseClient
Rst.Open "Select * From fl2", conn, adOpenKeyset, adLockPessimistic, adCmdText
End Sub
执行后,结果:至少一个参数没有被指定值!
黄条指在:If conn.Execute(strsql).EOF = False Then