type mismatch in DLookup

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
Don't delimit numeric values with " or ' character:

strWhere = "[DeliveryID]=" & strType
 
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
 
Back
Top