Error 13 Type Mismatch (1 Viewer)

Drand

Registered User.
Local time
Today, 16:54
Joined
Jun 8, 2019
Messages
179
Hi folks,

I am sure this really simple but I just can't seem to find what is wrong here.

The following code is creating an error 13 message. Strangely though, variables MyLatestDate and StockItem are returning the correct values. It is only the Dlookup where I am struggling.

Code:
Private Sub StockItem_AfterUpdate()
Dim MyLatestDate As Date
Dim StockItem As String
Dim StockNo As Integer

StockItem = Me.StockItem

MyLatestDate = DLookup("MaxofDateAdded", "QryLatestDateStockAdded", "MaxofDateAdded = #" _
 & DMax("MaxofDateAdded", "QryLatestDateStockAdded") & "#")


StockNo = DLookup("StockNumber", "tblStock", "StockItem =" & "'" & [StockItem] & "'" _
And "[Dateadded]= #" & [MyLatestDate] & "#")


End Sub

Would appreciate any assistance.

Many thanks
David
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:54
Joined
Feb 28, 2001
Messages
27,001
Just as a test, do this inside your event code:

Code:
StockItem = Me.StockItem

MyLatestDate = DMax( "MaxofDateAdded", "QryLatestDateStockAdded" )

MyLatestDate = DLookup("MaxofDateAdded", "QryLatestDateStockAdded", "MaxofDateAdded = #" _
 & MyLatestDate & "#")

StockNo = DLookup("StockNumber", "tblStock", "StockItem =" & "'" & [StockItem] & "'" _
And "[Dateadded]= #" & [MyLatestDate] & "#")

Using debugging, put your break on the first statement and Debug.Print MyLatestDate. Single step and hover the cursor over MyLatestDate in the Criteria of the DLookup. I'm curious to see what it tells you. I suspect a date formatting issue and splitting that DMax out of the DLookup would settle the doubt by letting you see what is coming out of the routine.
 

Drand

Registered User.
Local time
Today, 16:54
Joined
Jun 8, 2019
Messages
179
Thanks for the response. It is showing 12:00:00am
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:54
Joined
Oct 29, 2018
Messages
21,358
Hi. Just curious, which line is actually causing the error?
 

Drand

Registered User.
Local time
Today, 16:54
Joined
Jun 8, 2019
Messages
179
It is the line
StockNo = DLookup("StockNumber", "tblStock", "StockItem =" & "'" & [StockItem] & "'" _
And "[Dateadded]= #" & [MyLatestDate] & "#")
 

June7

AWF VIP
Local time
Yesterday, 21:54
Joined
Mar 9, 2014
Messages
5,424
The AND operator must be within quote marks because it is literal text:

StockNo = DLookup("StockNumber", "tblStock", "StockItem ='" & [StockItem] & "' AND [Dateadded]= #" & [MyLatestDate] & "#")
 

Drand

Registered User.
Local time
Today, 16:54
Joined
Jun 8, 2019
Messages
179
Thank you all. Quite right June7, this fixed it for me. Much appreciated
 

Users who are viewing this thread

Top Bottom