Dear Folk, I have three tables,
1- Customer from (TbCustomer)
2- Total numbers from (TbStore)
3- Return numbers from (TbOldSale)
Rest = Total numbers - Return numbers
Now I'm counting numbers for each Customer from TbStore as table shows
For Customer, Total numbers and Rest, code work fine but only with Field Return numbers I have error message shows error as attachment and code shows. Any help please. Thank you in advance
Note: I have field Return numbers in both tables (TbStore and TbOldSale). Thank you all.
------------------------------------------------------------------------------------
Code:
strSQL = "SELECT Customer_No, Customer_Name, Address, Fax, Phone FROM Customer"
Set rs1 = New ADODB.Recordset
rs1.Open strSQL, cnn, adOpenStatic, adLockOptimistic
Do Until rs1.EOF
'
' For this Customer count the number of entries for the given date
'
strSQL = "SELECT Count(*) AS Customer_NameCount FROM TbStore WHERE Customer_Name = '" & rs1![Customer_Name] & "' "
Set rs2 = New ADODB.Recordset
rs2.Open strSQL, cnn, adOpenStatic, adLockOptimistic
lngCount = rs2![Customer_NameCount]
rs2.Close
strSQL = "SELECT Count(*) AS NumberCount FROM TbOldSale WHERE Customer_Name = '" & rs1![Customer_Name] & "' AND ReturnDate <> '1900-01-01' "
rs2.Open strSQL, cnn, adOpenStatic, adLockOptimistic
lngActive = rs2![NumberCount]
'
' For this Customer count the active entries for the given date
ctr = ctr + 1
xlSheet1.Range("A" & CStr(ctr)).Value = rs1("Customer_No")
xlSheet1.Range("B" & CStr(ctr)).Value = rs1("Fax")
xlSheet1.Range("C" & CStr(ctr)).Value = rs1("Customer_Name")
xlSheet1.Range("D" & CStr(ctr)).Value = rs1("Address")
xlSheet1.Range("E" & CStr(ctr)).Value = rs1("Phone")
xlSheet1.Range("F" & CStr(ctr)).Value = lngCount
xlSheet1.Range("G" & CStr(ctr)).Value = lngActive
xlSheet1.Range("H" & CStr(ctr)).Value = lngCount - lngActive
rs2.Close
Set rs2 = Nothing
'
' Move on to the next Customer
'
rs1.MoveNext
Loop
1- Customer from (TbCustomer)
2- Total numbers from (TbStore)
3- Return numbers from (TbOldSale)
Rest = Total numbers - Return numbers
Now I'm counting numbers for each Customer from TbStore as table shows
Code:
Customer Total numbers Return numbers Rest
Mike 50 15 35
Note: I have field Return numbers in both tables (TbStore and TbOldSale). Thank you all.
------------------------------------------------------------------------------------
Code:
strSQL = "SELECT Customer_No, Customer_Name, Address, Fax, Phone FROM Customer"
Set rs1 = New ADODB.Recordset
rs1.Open strSQL, cnn, adOpenStatic, adLockOptimistic
Do Until rs1.EOF
'
' For this Customer count the number of entries for the given date
'
strSQL = "SELECT Count(*) AS Customer_NameCount FROM TbStore WHERE Customer_Name = '" & rs1![Customer_Name] & "' "
Set rs2 = New ADODB.Recordset
rs2.Open strSQL, cnn, adOpenStatic, adLockOptimistic
lngCount = rs2![Customer_NameCount]
rs2.Close
strSQL = "SELECT Count(*) AS NumberCount FROM TbOldSale WHERE Customer_Name = '" & rs1![Customer_Name] & "' AND ReturnDate <> '1900-01-01' "
rs2.Open strSQL, cnn, adOpenStatic, adLockOptimistic
lngActive = rs2![NumberCount]
'
' For this Customer count the active entries for the given date
ctr = ctr + 1
xlSheet1.Range("A" & CStr(ctr)).Value = rs1("Customer_No")
xlSheet1.Range("B" & CStr(ctr)).Value = rs1("Fax")
xlSheet1.Range("C" & CStr(ctr)).Value = rs1("Customer_Name")
xlSheet1.Range("D" & CStr(ctr)).Value = rs1("Address")
xlSheet1.Range("E" & CStr(ctr)).Value = rs1("Phone")
xlSheet1.Range("F" & CStr(ctr)).Value = lngCount
xlSheet1.Range("G" & CStr(ctr)).Value = lngActive
xlSheet1.Range("H" & CStr(ctr)).Value = lngCount - lngActive
rs2.Close
Set rs2 = Nothing
'
' Move on to the next Customer
'
rs1.MoveNext
Loop