Dcount question

rbinder

rbinder
Local time
Tomorrow, 05:10
Joined
Aug 13, 2005
Messages
25
Greetings all,

I have the code I use below but was now wondering if I can add another cirteria to base the dcount statement on. The code is in the beforeupdate() to allow me to avoid the duplicate.

What I would now like to add is that the Dcount is only calculated on say a particluar date, thus be a criteria in the table. ie I can have multiple locations but do not want to duplicate locations place on the same day.



Dim fBummer As Boolean
Dim iReply
Dim SID As String
Dim stLinkCriteria As String

SID = Me.Location.Value
stLinkCriteria = "[Location]=" & "'" & SID & "'"
If Len(Me.Location) > 3 Then
fBummer = (DCount("Location", "tbl_Data_Vessels", stLinkCriteria) <> 0)
If fBummer = True Then
iReply = MsgBox("The location " & SID & " has been used." & _
"Please enter the correct location", _
vbFatal + vbOKOnly, gstrAppTitle)
Cancel = True
End If
End If

thanks in advance

~rolf
 
Rolf,

Code:
stLinkCriteria = "[Location]=" & "'" & SID & "'"
If Len(Me.Location) > 3 And _
   DCount("Location", "tbl_Data_Vessels", "[Location] = '" & Me.Location & "' And " & _
                                          "[TheDate] = #' & Me.TheDate & "#") > 0
   MsgBox("The location " & Me.Location & " has been used." & _
          "Please enter the correct location", _
           vbFatal + vbOKOnly, gstrAppTitle)
   Cancel = True
End If

Wayne
 

Users who are viewing this thread

Back
Top Bottom