dcount (1 Viewer)

ssh

Registered User.
Local time
Today, 10:19
Joined
May 22, 2002
Messages
49
How to make the following accept numeric value?

Private Sub Kood_BeforeUpdate(Cancel As Integer)

If DCount("[Kood]", "asukohad", "[Kood]= '" & Me![Kood] & "'") = 1 Then
MsgBox "Already here."
Me.Undo
Cancel = True
End If

End Sub
 

DBL

Registered User.
Local time
Today, 10:19
Joined
Feb 20, 2002
Messages
659
Try:

If Not IsNull (DLookup("[Kood]", "asukohad", "[Kood]= '" & Me![Kood] & "'")) Then
MsgBox "Already here."
Me.Undo
Cancel = True
End If

End Sub
 

ssh

Registered User.
Local time
Today, 10:19
Joined
May 22, 2002
Messages
49
Didn't work, still says runtime error 3464: data type mismatch.
 

John.Woody

Registered User.
Local time
Today, 10:19
Joined
Sep 10, 2001
Messages
354
You could try turning it round:

If IsNull (DLookup("[Kood]", "asukohad", "[Kood]= '" & Me![Kood] & "'")) Then

....
Exit Sub
Else

MsgBox "Already here."
Me.Undo
Cancel = True
End If

End Sub
 
R

Rich

Guest
Try using the full reference to the control
DLookUp("FieldName","TableName","([FieldName] = '" & [Forms]![FormName]![FieldName] & "')")
 

ssh

Registered User.
Local time
Today, 10:19
Joined
May 22, 2002
Messages
49
Numeric, that's what cause problem.
 

DBL

Registered User.
Local time
Today, 10:19
Joined
Feb 20, 2002
Messages
659
If Not IsNull (DLookup("[Kood]", "asukohad", "[Kood]= " & Me![Kood])) Then
MsgBox "Already here."
Me.Undo
Cancel = True
End If

End Sub
 

ssh

Registered User.
Local time
Today, 10:19
Joined
May 22, 2002
Messages
49
Finally! Now accepts numeric. Thank you, DBL!
 

Users who are viewing this thread

Top Bottom