I'm working with a vb 6.0 application. There I'm using a replace function in my query. The query works fine in access but when it runs in vb it gives me the error:
"Undefined function 'Replace' in expression. Run-time error 3085".
I think that I'm missing references. I currently added following references.
The 'Replace' is located in the where clause:
...WHERE ((DateValue(Replace(Invoice.InvoiceDate, ': ', ' ')) Between...
The following full query is giving me the error.
Set DrsInv = db.OpenRecordset("SELECT Invoice.InvoiceDate, InvoicedProduct.InvoiceType, Invoice.InvoiceStatus, Invoice.RetailerID, Invoice.DailySalesID, Invoice.RepID, InvoicedProduct.Quantity, InvoicedProduct.UnitRate, InvoicedProduct.TotalItemValue From Invoice INNER JOIN InvoicedProduct ON (Invoice.DailySalesID = InvoicedProduct.DailySalesID) AND (Invoice.RepID = InvoicedProduct.RepID) AND (Invoice.InvoiceID = InvoicedProduct.InvoiceID)" _
& " WHERE ((DateValue(Replace(Invoice.InvoiceDate, ': ', ' ')) Between #" & Format(dtpFrom.value, "yyyy/mm/dd") & "# And #" & Format(dtpTo.value, "yyyy/mm/dd") & "#) AND (InvoicedProduct.ProductID = '" & Srs("ProductID") & "'))" _
& " GROUP BY Invoice.InvoiceDate, InvoicedProduct.InvoiceType, Invoice.InvoiceStatus, Invoice.RetailerID, Invoice.DailySalesID, Invoice.RepID, InvoicedProduct.Quantity, InvoicedProduct.UnitRate, InvoicedProduct.TotalItemValue HAVING ((InvoicedProduct.InvoiceType)='Invoice' AND (Invoice.InvoiceStatus)='VALID') Order By Invoice.InvoiceDate DESC")
I use the replace function because InvoiceDate is a text feild. So it is giving me the error "Data type mismatch", when I try to convert it to a date field in query. The colon inside the date is the reason for this error. That's why I need to replace the colon. I could not be able to change the database field. So this is the solution as the way I see it.
The data of the field InvoiceDate looks like following