BeardedSith
Member
- Local time
- Today, 18:36
- Joined
- Feb 5, 2020
- Messages
- 73
I ran into a data mismatch error and for some reason, I just can't seem to find where it is. I "think" I've narrowed it down to one column in one table, and it's a date entry. So...
Here is the function that keeps bugging out on me:
To get here, we go through several subqueries to create a list of eligibles for this INSERT statement:
sqryCalc0 (This isn't giving me any errors):
sqryCalc1 (This also doesn't give any errors):
sqryCalc2 (This is where the errors start):
sqryCalc3 (This also has the same error):
Looking at the two queries that are firing back errors, I had narrowed it down to either a date column or a currency column. So I surfed through the data and as far as I can tell, they're all in the tables correctly. It's only a handful of records, so it was pretty easy to fish through them looking for coherency. Which leads me to believe it's something to do with how these two queries are parsing dates and currency (more likely to be dates).
Something I tried while fishing through the data was the modify sqryCalc2 one column at a time until the mismatch error went away. Only when DatePurchase and the WHERE clause are removed do the errors cease. That leads me to believe that there's something fishy with the date columns. With some assumptions in tow, I feel like it has to do with how I'm handling CDate and RealDate(Which uses DateSerial and a row in the table).
Any ideas? More importantly, any tips and tricks on how to track this bug down a little easier?
I'm also including an image of the database setup for PurchaseDate within tbPurchases:
Here is the function that keeps bugging out on me:
Code:
Public Function IssueRewards()
Dim IssueSQL As String
IssueSQL = "INSERT INTO tblRewards ( CustomerID, IssueDate, IssueAmount )" _
& " SELECT qryEligibility.ID, Dateserial(Year(Now()),Month(Now()),Day(Now())) AS Today, qryEligibility.RealAmount" _
& " FROM qryEligibility" _
& " WHERE (((qryEligibility.IsEligible)=1))"
CurrentDb.Execute IssueSQL, dbFailOnError
Debug.Print IssueSQL
End Function
To get here, we go through several subqueries to create a list of eligibles for this INSERT statement:
sqryCalc0 (This isn't giving me any errors):
Code:
SELECT tbPurchases.MemberID, DateValue([PurchaseDate]) AS DatePurchase, tbPurchases.PurchaseAmount
FROM tblMembers INNER JOIN tbPurchases ON tblMembers.ID = tbPurchases.MemberID;
Code:
SELECT tblMembers.ID, Nz(IIf(Max([tblRewards]![IssueDate])<DateSerial(Year(Now()),1,1),DateSerial(Year(Now()),1,1),Max([tblRewards]![IssueDate])),DateSerial(Year(Now()),1,1)) AS RealDate
FROM tblRewards RIGHT JOIN tblMembers ON tblRewards.CustomerID = tblMembers.ID
GROUP BY tblMembers.ID;
Code:
SELECT sqryCalc0.MemberID, sqryCalc0.DatePurchase, Sum(sqryCalc0.PurchaseAmount) AS DailyPurchaseTotal
FROM sqryCalc0 INNER JOIN sqryCalc1 ON sqryCalc0.MemberID = sqryCalc1.ID
WHERE (((sqryCalc0.DatePurchase)>=[RealDate] And (sqryCalc0.DatePurchase)>=CDate("1/1/" & Year(Date()))))
GROUP BY sqryCalc0.MemberID, sqryCalc0.DatePurchase;
Code:
SELECT sqryCalc1.ID, Count(sqryCalc2.MemberID) AS NumPurchases, Sum(Nz([DailyPurchaseTotal],0)) AS SumOfPurchaseAmount, sqryCalc1.RealDate
FROM sqryCalc1 LEFT JOIN sqryCalc2 ON sqryCalc1.ID = sqryCalc2.MemberID
GROUP BY sqryCalc1.ID, sqryCalc1.RealDate;
Looking at the two queries that are firing back errors, I had narrowed it down to either a date column or a currency column. So I surfed through the data and as far as I can tell, they're all in the tables correctly. It's only a handful of records, so it was pretty easy to fish through them looking for coherency. Which leads me to believe it's something to do with how these two queries are parsing dates and currency (more likely to be dates).
Something I tried while fishing through the data was the modify sqryCalc2 one column at a time until the mismatch error went away. Only when DatePurchase and the WHERE clause are removed do the errors cease. That leads me to believe that there's something fishy with the date columns. With some assumptions in tow, I feel like it has to do with how I'm handling CDate and RealDate(Which uses DateSerial and a row in the table).
Any ideas? More importantly, any tips and tricks on how to track this bug down a little easier?
I'm also including an image of the database setup for PurchaseDate within tbPurchases: