type mismatch in DLookup

P

Penstar

I have the following code, which returns an error Runtime Error 2464 Data
Type Mismatch in Criteria expression

Private Sub Form_Delete(Cancel As Integer)
Dim varDeliveryID As Variant
Dim strType As Variant, strWhere As Variant

strType = Me.DeliveryID
strWhere = "[DeliveryID]=""" & strType & """"

If IsNull(DLookup("DeliveryID", "dbo_Orders", strWhere)) Then
Response = acDataErrContinue
Cancel = False

Else
MsgBox "The Delivery Customer contains orders. It cannot be deleted"
Cancel = True
End If
End Sub

All DeliveryID fields are set up as "Int" fields. I have tried putting
declarations as integer, but doesn't seem to help.

Thanks
Penny
 
A

Allen Browne

When you open your table in design view, it it shows the Delivery field is a
field of type Number, you don't need the extra quotes:
strWhere = "[DeliveryID] = " & Me.DeliveryID
 
K

Ken Snell \(MVP\)

Don't delimit numeric values with " or ' character:

strWhere = "[DeliveryID]=" & strType
 
P

Penstar

Thank You Allen & Ken, I have it working now. I really appreciate yuor help.

Ken Snell (MVP) said:
Don't delimit numeric values with " or ' character:

strWhere = "[DeliveryID]=" & strType

--

Ken Snell
<MS ACCESS MVP>



Penstar said:
I have the following code, which returns an error Runtime Error 2464 Data
Type Mismatch in Criteria expression

Private Sub Form_Delete(Cancel As Integer)
Dim varDeliveryID As Variant
Dim strType As Variant, strWhere As Variant

strType = Me.DeliveryID
strWhere = "[DeliveryID]=""" & strType & """"

If IsNull(DLookup("DeliveryID", "dbo_Orders", strWhere)) Then
Response = acDataErrContinue
Cancel = False

Else
MsgBox "The Delivery Customer contains orders. It cannot be deleted"
Cancel = True
End If
End Sub

All DeliveryID fields are set up as "Int" fields. I have tried putting
declarations as integer, but doesn't seem to help.

Thanks
Penny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top