flyingdutchman
11-07-2001, 02:42 AM
I'm building a form that is used to asign bednumbers. There can only be one bednumber asigned to a person each day. I've used a bit of code but that doesn't seem to work.
The following code is used.Private Sub Bednummer_AfterUpdate()
If Me!Bednummer = Bednummer And Datum = Date Then
MsgBox "Dit bed is al in gebruik. Geef een ander bednummer op"
End If
End Sub
can any body help me
The_Doc_Man
11-07-2001, 06:21 AM
Perhaps in a Bednummer_BeforeUpdate routine, which allows a Cancel parameter, you could do something like this - assuming Bednummer is truly numeric and if [Datum] is a date field. (You don't say the name of the table so I will use BedSched.)
Private Sub Bednummer_BeforeUpdate(Cancel as Integer)
Dim stQry as String
Dim loNum as Long
stQry = "[Bednummer] = " & CStr(Me![Bednummer]) & " and [Datum] = #" & Date$() & "#"
loNum = DCount( "[Bednummer]", "BedSched, stQry)
If loNum > 1 then
Cancel = -1
loNum = MsgBox( "Dit bed is al in gebruik. Geef een ander bednummer op")
Else
Cancel = 0
End If
End Sub
If [Bednummer] can include punctuation or text, then the query is
stQry = "[Bednummer] = """ & Me![Bednummer] & """ and [Datum] = #" & Date$() & "#"
flyingdutchman
11-08-2001, 11:20 PM
Thanx Doc_Man it worked. This has taken me a while but it works