T
tomanddani via AccessMonster.com
Im having a problem with some vba that checks for duplicate addresses. Im
getting a run time error #62506. Data type mismatch in criteria expression.
This is the vb code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strWhere As String
Dim varResult As Variant
Dim strMsg As String
If (Me.StreetNumber = Me.StreetNumber.OldValue) And (Me.Direction = Me.
Direction.OldValue) And (Me.StreetName = Me.StreetName.OldValue) Then
'do nothing
Else
strWhere = "([StreetNumber] = """ & Me.StreetNumber & """) AND (
[Direction] = """ & Me.Direction & """) AND ([StreetName] = """ & Me.
StreetName & """)"
varResult = DLookup("AddressID", "tblAddresses", strWhere)
If Not IsNull(varResult) Then
strMsg = "Duplicate of address " & varResult & vbCrLf & vbCrLf &
"CONTINUE ANYWAY?"
If MsgBox(strMsg, vbYesNo + vbDefaultButton2, "Warning") <> vbYes
Then
Cancel = True
Me.Undo
End If
End If
End If
End Sub
The error is in the:
varResult = DLookup("AddressID", "tblAddresses", strWhere)
line.
Im using a two tables called tblAddresses and tblBldgAndSystems. The form was
built by using a query called QAddressesAndBldgAndSystems. Im thinking that
Im just not refering to the objects the right way. Can anyone help.
Thanks
getting a run time error #62506. Data type mismatch in criteria expression.
This is the vb code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strWhere As String
Dim varResult As Variant
Dim strMsg As String
If (Me.StreetNumber = Me.StreetNumber.OldValue) And (Me.Direction = Me.
Direction.OldValue) And (Me.StreetName = Me.StreetName.OldValue) Then
'do nothing
Else
strWhere = "([StreetNumber] = """ & Me.StreetNumber & """) AND (
[Direction] = """ & Me.Direction & """) AND ([StreetName] = """ & Me.
StreetName & """)"
varResult = DLookup("AddressID", "tblAddresses", strWhere)
If Not IsNull(varResult) Then
strMsg = "Duplicate of address " & varResult & vbCrLf & vbCrLf &
"CONTINUE ANYWAY?"
If MsgBox(strMsg, vbYesNo + vbDefaultButton2, "Warning") <> vbYes
Then
Cancel = True
Me.Undo
End If
End If
End If
End Sub
The error is in the:
varResult = DLookup("AddressID", "tblAddresses", strWhere)
line.
Im using a two tables called tblAddresses and tblBldgAndSystems. The form was
built by using a query called QAddressesAndBldgAndSystems. Im thinking that
Im just not refering to the objects the right way. Can anyone help.
Thanks