I have a database that worked perfectly before, but today for some reason it has this error:
run time error 3464 data type mismatch
When I click debug, it pointed out the line that has the error:
Set rst = CurrentDb().OpenRecordset(strSQL) How could I fix it? Thank you!!!!
Below is my code:
Function DmdQtyThruDate(ItemVar As String, DatePeg As Date) As Double Dim rst As DAO.Recordset Dim strSQL As String strSQL = "SELECT Sum(TotQty) AS TotTotQty " strSQL = strSQL & "FROM (" strSQL = strSQL & "SELECT DISTINCTROW Sum([dbo_apsplan].[qty]) AS TotQty " strSQL = strSQL & "FROM [dbo_apsplan] LEFT JOIN [dbo_job_sch] ON (([dbo_apsplan].[ref_line_suf] = [dbo_job_sch].[suffix]) AND ([dbo_apsplan].[ref_num] = [dbo_job_sch].[job])) " strSQL = strSQL & "WHERE ([dbo_apsplan].[item]='" & ItemVar & "' AND [dbo_apsplan].[is_demand]=1 AND DateValue(IIf([dbo_apsplan].[ref_type]='j',[dbo_job_sch].[start_date],[dbo_apsplan].[due_date]))<=DateValue(#" & DatePeg & "#)) " strSQL = strSQL & "UNION ALL " strSQL = strSQL & "SELECT Sum([qty_ordered]-[qty_shipped]) AS TotQty " strSQL = strSQL & "FROM [dbo_coitem] " strSQL = strSQL & "WHERE (([item]='" & ItemVar & "') AND ([ref_num]is null) AND ([stat]='o' Or [stat]='p') AND (DateValue([due_date])<=DateValue(#" & DatePeg & "#)))); " Set rst = CurrentDb().OpenRecordset(strSQL) If rst.EOF = False Then DmdQtyThruDate = Nz(rst("TotTotQty"), 0) Else DmdQtyThruDate = 0 End If rst.Close Set rst = Nothing End Function
()afterCurrentDB? It's been a while since I did VBA in ms-access, but that feels wrong.([ref_num]is null)so([ref_num] is null).