Getting the following error.... <The expression you entered as a query parameter produced this error: 'rs!StoreID'>
rs!StoreID is an integer in the Stores table and prints out just fine in the msgbox function What am I doing wrong? I've used Dcount many times before, just not in a loop through the records in a table...
Thanks!
strSQL = "SELECT * FROM Stores"
Set rs = CurrentDb.OpenRecordset(strSQL)
If Not rs.BOF And Not rs.EOF Then
rs.MoveFirst
While (Not rs.EOF)
MsgBox ("Store: " & rs!StoreID & ", Name: " & rs!FullStoreName)
'Make sure data exists for Store in AccountBalances Table for start and end dates
If ((DCount("*", "AccountBalances", "[RecDate] = TempVars!varDate And [StoreID] = rs!StoreID") <= 0) Or _
(DCount("*", "AccountBalances", "[RecDate] = TempVars!varStartDate And [StoreID] = rs!StoreID") <= 0)) Then
NoData = NoData + 1
NoDataStoreList = NoDataStoreList & rs!FullStoreName & vbCrLf
End If
MsgBox ("Checking for CFS Orphans")
'Check if any Account Numbers for selected Store have Unassigned CFS Line Item in the AccountNumbers Table
NumRecs = DCount("*", "AccountNumbers", "[StoreID] = rs!StoreID And [CFS LineItem] = 0 And [Account Type] = '2-Assets'") _
+ DCount("*", "AccountNumbers", "[StoreID] = rs!StoreID And [CFS LineItem] = 0 And [Account Type] = '3-Liability'") _
+ DCount("*", "AccountNumbers", "[StoreID] = rs!StoreID And [CFS LineItem] = 0 And [Account Type] = '4-Net Worth'")
If (NumRecs > 0) Then
CFSOrphans = CFSOrphans + 1
CFSOrphansStoreList = CFSOrphansStoreList & rs!FullStoreName & " - " & NumRecs & " Accounts" & vbCrLf
End If
rs.MoveNext
Wend
End If
rs.Close
Set rs = Nothing