Using DCount to validate multiple fields (1 Viewer)

Sully

New member
Local time
Today, 11:17
Joined
Apr 15, 2014
Messages
2
Hi All

I am having an issue using DCount to validate against 3 fields within my database. I have a booking form which contains a Staff member, viewing slot, and Viewing Date which is used to book property viewings.

I want the form to check that the booking doesn't already exist when the process booking button is pressed.

I am using the following statement:

Code:
If DCount("*", "Viewing", "[Staff_ID]=" & Me.[Staff_ID] & " AND [Viewing_Period] = " & Me.Viewing_Period & "' AND Viewing_Date = '" & Me.Viewing_Date) & "'" > 0 Then
    MsgBox "Cannot book, booking already exists", vbCritical
End If

I always get the error "Syntax Error (Missing Operator)".

Can anybody help with this? Or let me know if there is a better way to do it. Sorry if its not explained properly, Im not that ofay with VB.

Much appreciated in advance.

Sully
 

pr2-eugin

Super Moderator
Local time
Today, 11:17
Joined
Nov 30, 2011
Messages
8,494
Is the Date actually a Date field? If so you need to enclose them between # and Strings between '

Something like,
Code:
If DCount("*", "Viewing", "[Staff_ID] = " & Me.[Staff_ID] & _
                          " AND [Viewing_Period] = [COLOR=Red][B]'[/B][/COLOR]" & Me.Viewing_Period & _
                          "[B][COLOR=Red]'[/COLOR][/B] AND [Viewing_Date] = "[COLOR=Red][B] & Format(Me.Viewing_Date, "\#mm\/dd\/yyyy\#")[/B][/COLOR]) > 0 Then
    MsgBox "Cannot book, booking already exists", vbCritical
End If
 

Sully

New member
Local time
Today, 11:17
Joined
Apr 15, 2014
Messages
2
You, my friend, are a genius! That worked wonderfully, although now I feel pretty stupid :)

Many thanks mate.

Sully
 

Users who are viewing this thread

Top Bottom