I need to generate a SQL statement for use in a recordset via VBA. I have 89000 records but when I run the query in VBA Module I have one record. The problem is the IIF statement. So I tried to use CASE WHEN but I get a "Missing Operator" Error. Thank you for you assistance in advance.
My code:
Public Function Load() As Double
Dim recnum As Double
Dim db As Database, rs As DAO.Recordset
Dim SQLString As Variant
SQLString = "SELECT Score.ScoreID, IIf([Value_True_30]=Yes,(Format([DValue_30],'Standard'))," _
& " (Format([Score_30],'Standard'))) AS Score30"
& " FROM Score" _
& " ORDER BY Score.ScoreID;"
Set db = CurrentDb
Set rs = db.OpenRecordset(SQLString)
recnum = rs.RecordCount
End Function
______________________
Here is the statement I tried to use:
SQLString = "SELECT Score.ScoreID, (Case When ([Value_True_30]=Yes) THEN [DValue_30] ELSE [Score_30] END ) as [Score30]" _
& " FROM Score ORDER BY Score.ScoreID;"
Thanks
Greg
My code:
Public Function Load() As Double
Dim recnum As Double
Dim db As Database, rs As DAO.Recordset
Dim SQLString As Variant
SQLString = "SELECT Score.ScoreID, IIf([Value_True_30]=Yes,(Format([DValue_30],'Standard'))," _
& " (Format([Score_30],'Standard'))) AS Score30"
& " FROM Score" _
& " ORDER BY Score.ScoreID;"
Set db = CurrentDb
Set rs = db.OpenRecordset(SQLString)
recnum = rs.RecordCount
End Function
______________________
Here is the statement I tried to use:
SQLString = "SELECT Score.ScoreID, (Case When ([Value_True_30]=Yes) THEN [DValue_30] ELSE [Score_30] END ) as [Score30]" _
& " FROM Score ORDER BY Score.ScoreID;"
Thanks
Greg