[RESOLVED] Another SQL Question
I am trying to get a percentage of how many products have been counted by using SQL statements. I have one that returns how many have been counted (checked) and another for how many have not been counted (needToCheck). I get a datatypoe mismatch when I try to equate the long variables to the connection execution. I was wondering if any knew how I could get the numbers I want easily rather than looping through the table twice. I would like to just be able to divide checked by needToCheck and multiply by 100 and output it to a label to let people know how far along they have come. Any suggestions? Thank you.
VB Code:
Private Sub completed()
Dim checked As Long
Dim needToCheck As Long
Dim sql As String
Set connection = New ADODB.connection
connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= G:\Finance\Inventory Control\CycleCount\DB\cycleCount.mdb"
connection.Open
sql = "SELECT Count(PROD) AS Expr1 " & _
"From TOGO " & _
"WHERE (((TOGO.CHECKED)=TRUE));"
checked = connection.Execute(sql)
sql = "SELECT Count(PROD) AS Expr1 " & _
"From TOGO " & _
"WHERE (((TOGO.CHECKED)=FALSE));"
needstoCheck = connection.Execute(sql)
End Sub
Re: [RESOLVED] Another SQL Question
Sigh, I hope you were able to figure out I was incorrect on what the fields were called. We were doing two "AS" Statements... like
Select (Select formula1 as Expr1 from tb1) As Checked
I went on the Expr1 but it was superseded by the second As and renamed to Checked. It's rs!Checked and rs!Unchecked. I modified my code to correct a second time. *Sigh*. Hate when that happens but anyway good luck!
Re: [RESOLVED] Another SQL Question
I think the original problem may have been expecting the SELECT statement to return a value, rather than a recordset, as Venus alluded to. I'd also second her/his practice of naming objects with a prefix - tblFoo, qryFoo, etc - to make it easier to see what you're dealing with in code.
I've had plenty of AAAGGGHHH!!! stories about dealing with legacy work where tables, fields, macros, queries, reports, etc, were all named the same thing, often with reserved words (Date being a common one). Don't do it.