captain27
10-22-2004, 06:04 PM
I have a column of nothing but amounts in currency.
I would like to take that all those amounts and put the sum in a textbox on my form. The amounts show up on a datagrid on my form which is connection using native adodc. My main form is connected using adodc1 controls.
Here is what I have so far.
-------------------------------------------------------
Public Sub accountlistload() ''datagridload'''
Dim sSql As String
Dim sSql1 As String
dim temp as currency
Dim rsInformation As New ADODB.Recordset
Dim mCnn As New ADODB.Connection
'''''connection for sum query'''
Dim rsInformation2 As New ADODB.Recordset
Dim mCnn2 As New ADODB.Connection
mCnn.Open "mhp"
mCnn2.Open "mhp"
sSql = "SELECT * FROM accountlist WHERE spaceno = " & Adodc1.Recordset("spaceno").Value
sSql1 = "SELECT SUM(amount)as temp from accountlist"
rsInformation.CursorLocation = adUseClient
rsInformation2.CursorLocation = adUseClient
rsInformation.Open sSql, mCnn, adOpenDynamic, adLockOptimistic
rsInformation2.Open sSql1, mCnn2, adOpenDynamic, adLockOptimistic
''''tempsum is the textbox for the sum result'''
Set temp = rsInformation2
tempsum.text = temp
tempsum.Refresh
Set DataGrid1.DataSource = rsInformation
DataGrid1.Refresh
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MovePrevious
End If
Set rsInformation = Nothing
Set mCnn = Nothing
Set rsInformation2 = Nothing
Set mCnn2 = Nothing
End Sub
------------------
do I really need two connections for the same table.
tempsum.text is on adodc1 control.
I would like to take that all those amounts and put the sum in a textbox on my form. The amounts show up on a datagrid on my form which is connection using native adodc. My main form is connected using adodc1 controls.
Here is what I have so far.
-------------------------------------------------------
Public Sub accountlistload() ''datagridload'''
Dim sSql As String
Dim sSql1 As String
dim temp as currency
Dim rsInformation As New ADODB.Recordset
Dim mCnn As New ADODB.Connection
'''''connection for sum query'''
Dim rsInformation2 As New ADODB.Recordset
Dim mCnn2 As New ADODB.Connection
mCnn.Open "mhp"
mCnn2.Open "mhp"
sSql = "SELECT * FROM accountlist WHERE spaceno = " & Adodc1.Recordset("spaceno").Value
sSql1 = "SELECT SUM(amount)as temp from accountlist"
rsInformation.CursorLocation = adUseClient
rsInformation2.CursorLocation = adUseClient
rsInformation.Open sSql, mCnn, adOpenDynamic, adLockOptimistic
rsInformation2.Open sSql1, mCnn2, adOpenDynamic, adLockOptimistic
''''tempsum is the textbox for the sum result'''
Set temp = rsInformation2
tempsum.text = temp
tempsum.Refresh
Set DataGrid1.DataSource = rsInformation
DataGrid1.Refresh
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MovePrevious
End If
Set rsInformation = Nothing
Set mCnn = Nothing
Set rsInformation2 = Nothing
Set mCnn2 = Nothing
End Sub
------------------
do I really need two connections for the same table.
tempsum.text is on adodc1 control.