Conrado Natac
New Member
I get a syntax error on the sum code, how do I use the sum in sql
I want to use the sum to total the amount per invoice
'here is my complete code
Option Explicit
Public cnn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public strSQL As String
Public Sub OpenDB()
If cnn.State = adStateOpen Then cnn.Close
cnn.ConnectionString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" & _
ThisWorkbook.Path & Application.PathSeparator & ThisWorkbook.Name
cnn.Open
End Sub
Public Sub closeRS()
If rs.State = adStateOpen Then rs.Close
rs.CursorLocation = adUseClient
End Sub
'here is the error
Private Sub cmdbalance_Click()
'this gets the balance of an invoice, after payments
' per one customer
Sheets("View").Visible = True
Sheets("View").Select
Range("A30:N40000").ClearContents
closeRS
OpenDB
closeRS
'this is the connrection
OpenDB
'this is the error
rs.Open "SELECT Distinct [Inv #], [Cust #], [Date],[Due Date], sum[Amount] as InvBal FROM [data$] WHERE [data$].[Cust #]=" & "'" & cmbcustno.Text & "'", _
cnn, adOpenKeyset, adLockOptimistic
'dispose the connection
Set cnn = Nothing
If rs.RecordCount > 0 Then
Sheets("View").Visible = True
Sheets("View").Select
'Range("dataSet").Select
'Range(Selection, Selection.End(xlDown)).ClearContents
Range("A30").Select
'Now putting the data on the sheet
ActiveCell.CopyFromRecordset rs
Else
'dispose the recordeset
Set rs = Nothing
Exit Sub
i got
End If
'dispose the recordeset
Set rs = Nothing
End Sub
I want to use the sum to total the amount per invoice
'here is my complete code
Option Explicit
Public cnn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public strSQL As String
Public Sub OpenDB()
If cnn.State = adStateOpen Then cnn.Close
cnn.ConnectionString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" & _
ThisWorkbook.Path & Application.PathSeparator & ThisWorkbook.Name
cnn.Open
End Sub
Public Sub closeRS()
If rs.State = adStateOpen Then rs.Close
rs.CursorLocation = adUseClient
End Sub
'here is the error
Private Sub cmdbalance_Click()
'this gets the balance of an invoice, after payments
' per one customer
Sheets("View").Visible = True
Sheets("View").Select
Range("A30:N40000").ClearContents
closeRS
OpenDB
closeRS
'this is the connrection
OpenDB
'this is the error
rs.Open "SELECT Distinct [Inv #], [Cust #], [Date],[Due Date], sum[Amount] as InvBal FROM [data$] WHERE [data$].[Cust #]=" & "'" & cmbcustno.Text & "'", _
cnn, adOpenKeyset, adLockOptimistic
'dispose the connection
Set cnn = Nothing
If rs.RecordCount > 0 Then
Sheets("View").Visible = True
Sheets("View").Select
'Range("dataSet").Select
'Range(Selection, Selection.End(xlDown)).ClearContents
Range("A30").Select
'Now putting the data on the sheet
ActiveCell.CopyFromRecordset rs
Else
'dispose the recordeset
Set rs = Nothing
Exit Sub
i got
End If
'dispose the recordeset
Set rs = Nothing
End Sub