DCount problem (1 Viewer)

edojanssen

Registered User.
Local time
Today, 17:22
Joined
Jun 21, 2006
Messages
23
I'm building a db which holds vehicles and their driver. The form Vehicles has a subform which contains the drivers and the begindate and enddate. What I want is to secure this form so that no duplicate records can be made. If you enter a drivers name there must be a check that the driver is not on another vehicle and no enddate. When the enddate is added, the driver can be selected to be entered on other vehicles.

I already tried but I get a syntax error:
Code:
    If DCount("[Bestuurder]", "qryBestuurderCheck", "[Bestuurder]='" & Forms![sfrmKentekens]![Bestuurder] & "'") Then '> 0 Then
        MsgBox "De gekozen bestuurder bestaat al " & _
        vbCrLf & "bij een ander kenteken!"
        Me.Bestuurder.Undo
    Else
    End If

Who can help me out?
 

Alc

Registered User.
Local time
Today, 11:22
Joined
Mar 23, 2007
Messages
2,407
Is this any better?
Code:
If DCount("Bestuurder", "qryBestuurderCheck", "Bestuurder = '" & Forms![sfrmKentekens]![Bestuurder] & "'") > 0 Then
        MsgBox "De gekozen bestuurder bestaat al " & _
        vbCrLf & "bij een ander kenteken!"
        Me.Bestuurder.Undo
End If
 

edojanssen

Registered User.
Local time
Today, 17:22
Joined
Jun 21, 2006
Messages
23
It doesn't work. Now I got error 2450: 'can't find form sfrmKentekens'.

I've put the code in the before_update-event of the field [Bestuurder] in the subform sfrmKentekens. Don't know if that makes any difference.
 

Alc

Registered User.
Local time
Today, 11:22
Joined
Mar 23, 2007
Messages
2,407
At the risk of sounding patronising (but honestly not meaning to), is the form definitely called 'sfrmKentekens'?
 

edojanssen

Registered User.
Local time
Today, 17:22
Joined
Jun 21, 2006
Messages
23
The subform is called sfrmKentekens, the mainform is frmKentekens. I've attached a part of my db. I hope this will make it easier to solve the problem.
 

Attachments

  • Test.zip
    40 KB · Views: 101

Alc

Registered User.
Local time
Today, 11:22
Joined
Mar 23, 2007
Messages
2,407
Soryy about the delay, the boss was insisting I actual did some work (the nerve! :D)

I tried changing the expression to
Code:
If DCount("Bestuurder", "qryBestuurderCheck", "Bestuurder = '" & Me![Bestuurder] & "'") > 0 Then
        MsgBox "De gekozen bestuurder bestaat al " & _
        vbCrLf & "bij een ander kenteken!"
        Me.Bestuurder.Undo
End If
It now runs, and I got the message displayed on the few I tested it for, but my German(?) isn't up to knowing if it's displaying it when it should.
 

edojanssen

Registered User.
Local time
Today, 17:22
Joined
Jun 21, 2006
Messages
23
Hi Alc,

It's working like the way I wanted. I've changed the msgBox a little so the user will know at which vehicle the double driver excists.

Code:
Dim strKenteken As String
strKenteken = DLookup("Kenteken", "qryBestuurderCheck", "Bestuurder = '" & Me![Bestuurder] & "'")

If DCount("Bestuurder", "qryBestuurderCheck", "Bestuurder = '" & Me![Bestuurder] & "'") > 0 Then
        MsgBox "De gekozen bestuurder bestaat al " & _
        vbCrLf & "bij kenteken " & strKenteken & "!"
        Me.Undo
End If

I've added your name to the credits of the program.
Thanks a lot
Edo
 

Alc

Registered User.
Local time
Today, 11:22
Joined
Mar 23, 2007
Messages
2,407
No problem, glad to be of help and thanks for letting me know it worked out okay.
 

Users who are viewing this thread

Top Bottom