Duplicate value check

S

srn

My form records patient attendance, time of attendance, date of attendance
and a number. These are recorded onto an attendance table called SCAN.
The following code is called in the afterupdate of the number field.
I want it to check the scan table to highlight if this patient has already
attended today, and to return a message box informing the operator that the
patient has attended and the time at which they attended. Some patients may
attend more than once, so it is purely to highlight and inform the operator.
A variety of errors have been generated however i have solved those and now
i am recieving a run time error 13, at the "else varDose Supplied...." line.
Help


Public Function CheckDuplicates()
Dim varDoseSupplied As Variant
If IsNull(Me.IDSurname) Or IsNull(Me.Date) Then CheckDuplicates = False _
Else varDoseSupplied = DLookup("Time", "Scan", "date= " & Me.Date & "" And
IDSurname = " & me.idsurname")
If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly

CheckDuplicates = True
Else
CheckDuplicates = False
End If

End Function
 
A

Arvin Meyer [MVP]

Two possible errors. Error 13 is a datatype mismatch and you'll need to
surround your value with # like

DLookup("Time", "Scan", "Time= #" & Me.[Date] & "#")

The other possible problem is that you are using Date, a reserved word, as a
control name (and probably a field name, as well). It is better to change
it, but if that's not possible, at least use:

Me.[Date]
 
S

srn

I have tried both of these but error 13 still is triggered. Any other ideas?

Arvin Meyer said:
Two possible errors. Error 13 is a datatype mismatch and you'll need to
surround your value with # like

DLookup("Time", "Scan", "Time= #" & Me.[Date] & "#")

The other possible problem is that you are using Date, a reserved word, as a
control name (and probably a field name, as well). It is better to change
it, but if that's not possible, at least use:

Me.[Date]
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

srn said:
My form records patient attendance, time of attendance, date of attendance
and a number. These are recorded onto an attendance table called SCAN.
The following code is called in the afterupdate of the number field.
I want it to check the scan table to highlight if this patient has already
attended today, and to return a message box informing the operator that
the
patient has attended and the time at which they attended. Some patients
may
attend more than once, so it is purely to highlight and inform the
operator.
A variety of errors have been generated however i have solved those and
now
i am recieving a run time error 13, at the "else varDose Supplied...."
line.
Help


Public Function CheckDuplicates()
Dim varDoseSupplied As Variant
If IsNull(Me.IDSurname) Or IsNull(Me.Date) Then CheckDuplicates = False _
Else varDoseSupplied = DLookup("Time", "Scan", "date= " & Me.Date & "" And
IDSurname = " & me.idsurname")
If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly

CheckDuplicates = True
Else
CheckDuplicates = False
End If

End Function
 
S

Steve Sanford

PMFJI,

The syntax for the first IF() statement is wrong. You can't mix the single
line version of the IF() statement with the block form.

And like Arvin said, "Date" and 'Time " are reserved words in Access. For a
list of reserved words, see:

http://allenbrowne.com/AppIssueBadWord.html


I modified your code (for the first IF() statement):

(watch for line wrap!!!)
'------- beg code -------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

If IsNull(Me.IDSurname) Or IsNull(Me.[Date]) Then
CheckDuplicates = False
Else
varDoseSupplied = DLookup("Time", "Scan", "[date]= " & Me.[Date] & ""
And IDSurname = " & me.idsurname")
End If

If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
CheckDuplicates = True
Else
CheckDuplicates = False
End If

End Function
'------- beg code -------------------



In trying to understand your code, I rewrote it. Maybe it will be helpful

(watch for line wrap!!!)
'---------- end code -------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

' if date and IDsurname entered, lookup dose time
If Not IsNull(Me.IDSurname) Or Not IsNull(Me.[Date]) Then
varDoseSupplied = DLookup("[Time]", "Scan", "[date]= " & Me.[Date] & ""
And IDSurname = " & me.idsurname")

End If

CheckDuplicates = Not IsNull(varDoseSupplied)

' show message
If CheckDuplicates Then

MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly

End If

End Function
'---------- end code -------------------


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


srn said:
I have tried both of these but error 13 still is triggered. Any other ideas?

Arvin Meyer said:
Two possible errors. Error 13 is a datatype mismatch and you'll need to
surround your value with # like

DLookup("Time", "Scan", "Time= #" & Me.[Date] & "#")

The other possible problem is that you are using Date, a reserved word, as a
control name (and probably a field name, as well). It is better to change
it, but if that's not possible, at least use:

Me.[Date]
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

srn said:
My form records patient attendance, time of attendance, date of attendance
and a number. These are recorded onto an attendance table called SCAN.
The following code is called in the afterupdate of the number field.
I want it to check the scan table to highlight if this patient has already
attended today, and to return a message box informing the operator that
the
patient has attended and the time at which they attended. Some patients
may
attend more than once, so it is purely to highlight and inform the
operator.
A variety of errors have been generated however i have solved those and
now
i am recieving a run time error 13, at the "else varDose Supplied...."
line.
Help


Public Function CheckDuplicates()
Dim varDoseSupplied As Variant
If IsNull(Me.IDSurname) Or IsNull(Me.Date) Then CheckDuplicates = False _
Else varDoseSupplied = DLookup("Time", "Scan", "date= " & Me.Date & "" And
IDSurname = " & me.idsurname")
If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly

CheckDuplicates = True
Else
CheckDuplicates = False
End If

End Function
 
S

srn

Thanks steve
I've tried the changes but still generating errors. Maybe i need to come at
this from a different angle.
I run a query of the scan table selecting records where date = date().
The results are then displayed on a subform/report.
Do you think i can look up this and compare IDSurname only, thus avoiding
the date issues?

Steve Sanford said:
PMFJI,

The syntax for the first IF() statement is wrong. You can't mix the single
line version of the IF() statement with the block form.

And like Arvin said, "Date" and 'Time " are reserved words in Access. For a
list of reserved words, see:

http://allenbrowne.com/AppIssueBadWord.html


I modified your code (for the first IF() statement):

(watch for line wrap!!!)
'------- beg code -------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

If IsNull(Me.IDSurname) Or IsNull(Me.[Date]) Then
CheckDuplicates = False
Else
varDoseSupplied = DLookup("Time", "Scan", "[date]= " & Me.[Date] & ""
And IDSurname = " & me.idsurname")
End If

If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
CheckDuplicates = True
Else
CheckDuplicates = False
End If

End Function
'------- beg code -------------------



In trying to understand your code, I rewrote it. Maybe it will be helpful

(watch for line wrap!!!)
'---------- end code -------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

' if date and IDsurname entered, lookup dose time
If Not IsNull(Me.IDSurname) Or Not IsNull(Me.[Date]) Then
varDoseSupplied = DLookup("[Time]", "Scan", "[date]= " & Me.[Date] & ""
And IDSurname = " & me.idsurname")

End If

CheckDuplicates = Not IsNull(varDoseSupplied)

' show message
If CheckDuplicates Then

MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly

End If

End Function
'---------- end code -------------------


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


srn said:
I have tried both of these but error 13 still is triggered. Any other ideas?

Arvin Meyer said:
Two possible errors. Error 13 is a datatype mismatch and you'll need to
surround your value with # like

DLookup("Time", "Scan", "Time= #" & Me.[Date] & "#")

The other possible problem is that you are using Date, a reserved word, as a
control name (and probably a field name, as well). It is better to change
it, but if that's not possible, at least use:

Me.[Date]
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

My form records patient attendance, time of attendance, date of attendance
and a number. These are recorded onto an attendance table called SCAN.
The following code is called in the afterupdate of the number field.
I want it to check the scan table to highlight if this patient has already
attended today, and to return a message box informing the operator that
the
patient has attended and the time at which they attended. Some patients
may
attend more than once, so it is purely to highlight and inform the
operator.
A variety of errors have been generated however i have solved those and
now
i am recieving a run time error 13, at the "else varDose Supplied...."
line.
Help


Public Function CheckDuplicates()
Dim varDoseSupplied As Variant
If IsNull(Me.IDSurname) Or IsNull(Me.Date) Then CheckDuplicates = False _
Else varDoseSupplied = DLookup("Time", "Scan", "date= " & Me.Date & "" And
IDSurname = " & me.idsurname")
If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly

CheckDuplicates = True
Else
CheckDuplicates = False
End If

End Function
 
S

Steve Sanford

OK, I know you have a table named "SCAN".
What are the names of the *fields* for:

patient attendance
time of attendance
date of attendance
a number


I know you have a form with at least 2 controls. What are the names of the
*controls*?

Do you have a text box named "date"?
Again, "Date" is a very bad name for a field of control. It is not very
descriptive.... date of What?? So you could have a *field* named date, a
control named *date* and there is a built in function named *date*. How
confusing...

In your DLOOKUP, you have "

/snip/ "date= " & Me.Date & " /snip/

Is Me.date the name of a control on the form? Or are you trying to get
today's date?


I made a table (SCAN) and entered some test data. I changed the field names
to differentiate the control names from the field names (and so I wouldn't be
as confused).

I made a form with three controls, a text box for a date, a text box for
idsurname and a button.

I tweeked the functions and got them to run without errors.

Your function: (watch for line wrap)

'---------------------------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

If IsNull(Me.tbIDsurname) Or IsNull(Me.[tbAttendDate]) Then
CheckDuplicates = False
Else
varDoseSupplied = DLookup("attendTime", "Scan", "[attenddate]= #" &
Me.[tbAttendDate] & "# And IDSurname = " & Me.tbIDsurname)
End If

If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
CheckDuplicates = True
Else
CheckDuplicates = False
End If

End Function
'------------------------------------

Mine: (watch for line wrap)
'------------------------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

' if date and IDsurname entered, lookup dose time
If Not IsNull(Me.tbIDsurname) Or Not IsNull(Me.[tbAttendDate]) Then
varDoseSupplied = DLookup("attendTime", "Scan", "[attenddate]= #" &
Me.[tbAttendDate] & "# And IDSurname = " & Me.tbIDsurname)
End If

CheckDuplicates = Not IsNull(varDoseSupplied)

' show message
If CheckDuplicates Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
End If

End Function
'------------------------------------


Another way would be to open a recordset based on the query for the subform
and check if the record count is GT 0. If the record count is GT 0 then
display a message that record(s) were found and the time of attendance.
The code would look something like:

(watch for line wrap)
'---------------------------
Public Sub CheckDuplicates()
Dim rs As DAO.Recordset
Dim strSQL As String
Dim varDoseSupplied As Variant

strSQL = "Select attendTime FROM SCAN"
strSQL = strSQL & " WHERE attendDate = #" & Me.[tbAttendDate] & "#"
strSQL = strSQL & " And SCAN.idsurname = " & Me.[tbIDsurname]
strSQL = strSQL & " ORDER BY SCAN.attendTime DESC , SCAN.attendDate DESC;"


Set rs = CurrentDb.OpenRecordset(strSQL)
If Not rs.EOF And Not rs.EOF Then
rs.MoveLast
rs.MoveFirst
varDoseSupplied = rs!attendTime
End If

If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
End If

rs.Close
Set rs = Nothing

End Sub
'---------------------------


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


srn said:
Thanks steve
I've tried the changes but still generating errors. Maybe i need to come at
this from a different angle.
I run a query of the scan table selecting records where date = date().
The results are then displayed on a subform/report.
Do you think i can look up this and compare IDSurname only, thus avoiding
the date issues?

Steve Sanford said:
PMFJI,

The syntax for the first IF() statement is wrong. You can't mix the single
line version of the IF() statement with the block form.

And like Arvin said, "Date" and 'Time " are reserved words in Access. For a
list of reserved words, see:

http://allenbrowne.com/AppIssueBadWord.html


I modified your code (for the first IF() statement):

(watch for line wrap!!!)
'------- beg code -------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

If IsNull(Me.IDSurname) Or IsNull(Me.[Date]) Then
CheckDuplicates = False
Else
varDoseSupplied = DLookup("Time", "Scan", "[date]= " & Me.[Date] & ""
And IDSurname = " & me.idsurname")
End If

If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
CheckDuplicates = True
Else
CheckDuplicates = False
End If

End Function
'------- beg code -------------------



In trying to understand your code, I rewrote it. Maybe it will be helpful

(watch for line wrap!!!)
'---------- end code -------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

' if date and IDsurname entered, lookup dose time
If Not IsNull(Me.IDSurname) Or Not IsNull(Me.[Date]) Then
varDoseSupplied = DLookup("[Time]", "Scan", "[date]= " & Me.[Date] & ""
And IDSurname = " & me.idsurname")

End If

CheckDuplicates = Not IsNull(varDoseSupplied)

' show message
If CheckDuplicates Then

MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly

End If

End Function
'---------- end code -------------------


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


srn said:
I have tried both of these but error 13 still is triggered. Any other ideas?

:

Two possible errors. Error 13 is a datatype mismatch and you'll need to
surround your value with # like

DLookup("Time", "Scan", "Time= #" & Me.[Date] & "#")

The other possible problem is that you are using Date, a reserved word, as a
control name (and probably a field name, as well). It is better to change
it, but if that's not possible, at least use:

Me.[Date]
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

My form records patient attendance, time of attendance, date of attendance
and a number. These are recorded onto an attendance table called SCAN.
The following code is called in the afterupdate of the number field.
I want it to check the scan table to highlight if this patient has already
attended today, and to return a message box informing the operator that
the
patient has attended and the time at which they attended. Some patients
may
attend more than once, so it is purely to highlight and inform the
operator.
A variety of errors have been generated however i have solved those and
now
i am recieving a run time error 13, at the "else varDose Supplied...."
line.
Help


Public Function CheckDuplicates()
Dim varDoseSupplied As Variant
If IsNull(Me.IDSurname) Or IsNull(Me.Date) Then CheckDuplicates = False _
Else varDoseSupplied = DLookup("Time", "Scan", "date= " & Me.Date & "" And
IDSurname = " & me.idsurname")
If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly

CheckDuplicates = True
Else
CheckDuplicates = False
End If

End Function
 
S

srn

Hi Steve
Thanks for all the effort and help.

My table called scan has the following fields:
IDScan - autonumber
IDSurname - number - lookup of the Patient details table giving: IDSurname
(a pateint number), Surname (Patients surname) and Address (Patients Address)
Time - date/time
Date - date/time
Days - text


My form called Scan has the following:
IDSurname - combobox - displays IDSurname, Surname and Address from the
Patient details table
Days - text box - records the number of doses dispensed
Time - text box - control source set to time
Date - text box - control source set to Date

I have a Subform callled ScanDailyAttendance:
This is based on a query of the scan table. It displays IDSurname, Surname,
Date, Time and Days. The results displayed are where the scan table date =
todays date.


The me.date refers to the date displayed in the date text box on the form.

This is a large database with approx 300,000 scan records, 2000 patients
records, 45,000 prescription records. The databease has evolved as i have
required more info and funtionality. This is why naming conventions have been
confused.
Stuart



Steve Sanford said:
OK, I know you have a table named "SCAN".
What are the names of the *fields* for:

patient attendance
time of attendance
date of attendance
a number


I know you have a form with at least 2 controls. What are the names of the
*controls*?

Do you have a text box named "date"?
Again, "Date" is a very bad name for a field of control. It is not very
descriptive.... date of What?? So you could have a *field* named date, a
control named *date* and there is a built in function named *date*. How
confusing...

In your DLOOKUP, you have "

/snip/ "date= " & Me.Date & " /snip/

Is Me.date the name of a control on the form? Or are you trying to get
today's date?


I made a table (SCAN) and entered some test data. I changed the field names
to differentiate the control names from the field names (and so I wouldn't be
as confused).

I made a form with three controls, a text box for a date, a text box for
idsurname and a button.

I tweeked the functions and got them to run without errors.

Your function: (watch for line wrap)

'---------------------------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

If IsNull(Me.tbIDsurname) Or IsNull(Me.[tbAttendDate]) Then
CheckDuplicates = False
Else
varDoseSupplied = DLookup("attendTime", "Scan", "[attenddate]= #" &
Me.[tbAttendDate] & "# And IDSurname = " & Me.tbIDsurname)
End If

If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
CheckDuplicates = True
Else
CheckDuplicates = False
End If

End Function
'------------------------------------

Mine: (watch for line wrap)
'------------------------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

' if date and IDsurname entered, lookup dose time
If Not IsNull(Me.tbIDsurname) Or Not IsNull(Me.[tbAttendDate]) Then
varDoseSupplied = DLookup("attendTime", "Scan", "[attenddate]= #" &
Me.[tbAttendDate] & "# And IDSurname = " & Me.tbIDsurname)
End If

CheckDuplicates = Not IsNull(varDoseSupplied)

' show message
If CheckDuplicates Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
End If

End Function
'------------------------------------


Another way would be to open a recordset based on the query for the subform
and check if the record count is GT 0. If the record count is GT 0 then
display a message that record(s) were found and the time of attendance.
The code would look something like:

(watch for line wrap)
'---------------------------
Public Sub CheckDuplicates()
Dim rs As DAO.Recordset
Dim strSQL As String
Dim varDoseSupplied As Variant

strSQL = "Select attendTime FROM SCAN"
strSQL = strSQL & " WHERE attendDate = #" & Me.[tbAttendDate] & "#"
strSQL = strSQL & " And SCAN.idsurname = " & Me.[tbIDsurname]
strSQL = strSQL & " ORDER BY SCAN.attendTime DESC , SCAN.attendDate DESC;"


Set rs = CurrentDb.OpenRecordset(strSQL)
If Not rs.EOF And Not rs.EOF Then
rs.MoveLast
rs.MoveFirst
varDoseSupplied = rs!attendTime
End If

If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
End If

rs.Close
Set rs = Nothing

End Sub
'---------------------------


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


srn said:
Thanks steve
I've tried the changes but still generating errors. Maybe i need to come at
this from a different angle.
I run a query of the scan table selecting records where date = date().
The results are then displayed on a subform/report.
Do you think i can look up this and compare IDSurname only, thus avoiding
the date issues?

Steve Sanford said:
PMFJI,

The syntax for the first IF() statement is wrong. You can't mix the single
line version of the IF() statement with the block form.

And like Arvin said, "Date" and 'Time " are reserved words in Access. For a
list of reserved words, see:

http://allenbrowne.com/AppIssueBadWord.html


I modified your code (for the first IF() statement):

(watch for line wrap!!!)
'------- beg code -------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

If IsNull(Me.IDSurname) Or IsNull(Me.[Date]) Then
CheckDuplicates = False
Else
varDoseSupplied = DLookup("Time", "Scan", "[date]= " & Me.[Date] & ""
And IDSurname = " & me.idsurname")
End If

If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
CheckDuplicates = True
Else
CheckDuplicates = False
End If

End Function
'------- beg code -------------------



In trying to understand your code, I rewrote it. Maybe it will be helpful

(watch for line wrap!!!)
'---------- end code -------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

' if date and IDsurname entered, lookup dose time
If Not IsNull(Me.IDSurname) Or Not IsNull(Me.[Date]) Then
varDoseSupplied = DLookup("[Time]", "Scan", "[date]= " & Me.[Date] & ""
And IDSurname = " & me.idsurname")

End If

CheckDuplicates = Not IsNull(varDoseSupplied)

' show message
If CheckDuplicates Then

MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly

End If

End Function
'---------- end code -------------------


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

I have tried both of these but error 13 still is triggered. Any other ideas?

:

Two possible errors. Error 13 is a datatype mismatch and you'll need to
surround your value with # like

DLookup("Time", "Scan", "Time= #" & Me.[Date] & "#")

The other possible problem is that you are using Date, a reserved word, as a
control name (and probably a field name, as well). It is better to change
it, but if that's not possible, at least use:

Me.[Date]
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

My form records patient attendance, time of attendance, date of attendance
and a number. These are recorded onto an attendance table called SCAN.
The following code is called in the afterupdate of the number field.
I want it to check the scan table to highlight if this patient has already
attended today, and to return a message box informing the operator that
the
patient has attended and the time at which they attended. Some patients
may
attend more than once, so it is purely to highlight and inform the
operator.
A variety of errors have been generated however i have solved those and
now
i am recieving a run time error 13, at the "else varDose Supplied...."
line.
Help


Public Function CheckDuplicates()
Dim varDoseSupplied As Variant
If IsNull(Me.IDSurname) Or IsNull(Me.Date) Then CheckDuplicates = False _
Else varDoseSupplied = DLookup("Time", "Scan", "date= " & Me.Date & "" And
IDSurname = " & me.idsurname")
If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly

CheckDuplicates = True
Else
CheckDuplicates = False
End If

End Function
 
S

Steve Sanford

Stuart,

Sorry its taken so long to get back to you... work interferes with fun (as
usual).

OK, as I understand your setup:

Table name: PatientDetails
==================
IDSurname - PK - autonumber or custom number
Surname - text
Address - text

Table name: SCAN
=============
IDScan - autonumber
IDSurname - FK to PatientDetails
Time - date/time (of dose)
Date - date/time (of dose)
Days - text (records the number of doses dispensed)

Main form: Scan
============
Recordsource - Unbound(??)

Controls on form: (all unbound??)
-------------------------------------
IDSurname - combobox - displays IDSurname, Surname and Address from the
Patient details table
Days - text box - records the number of doses dispensed
Time - text box - control source set to time
Date - text box - control source set to Date

subform: ScanDailyAttendance
============
Recordsource - (??)

Controls on subform:
------------------------
IDSurname
Surname
Date
Time
Days


On the main form, where are the controls places - in the header or in the
details section?

Can you add "IDSurname" to the WHERE clause of the subform query? then when
you select the Patient using the combo box on the mainform ("Scan"), the
subform would only show the doses for that day and patient.


I retested the functions "CheckDuplicates" (both of them) and they seem to
work. If the function "CheckDuplicates" is in a standard module, the name of
the module must not be the same as the function.

Have you stepped thru the code to see where the error occurs? What errors
are you getting?



###############
BTW, here are links to "Rearch and Replace" tools that find and rename
objects in the database:

Free
MDBSearch: http://www3.bc.sympatico.ca/starthere/findandreplace

$$
Find and Replace: http://www.rickworld.com
Speed Ferret: http://www.moshannon.com
Total Access Analyzer: http://www.fmsinc.com
###############



HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


srn said:
Hi Steve
Thanks for all the effort and help.

My table called scan has the following fields:
IDScan - autonumber
IDSurname - number - lookup of the Patient details table giving: IDSurname
(a pateint number), Surname (Patients surname) and Address (Patients Address)
Time - date/time
Date - date/time
Days - text


My form called Scan has the following:
IDSurname - combobox - displays IDSurname, Surname and Address from the
Patient details table
Days - text box - records the number of doses dispensed
Time - text box - control source set to time
Date - text box - control source set to Date

I have a Subform callled ScanDailyAttendance:
This is based on a query of the scan table. It displays IDSurname, Surname,
Date, Time and Days. The results displayed are where the scan table date =
todays date.


The me.date refers to the date displayed in the date text box on the form.

This is a large database with approx 300,000 scan records, 2000 patients
records, 45,000 prescription records. The databease has evolved as i have
required more info and funtionality. This is why naming conventions have been
confused.
Stuart



Steve Sanford said:
OK, I know you have a table named "SCAN".
What are the names of the *fields* for:

patient attendance
time of attendance
date of attendance
a number


I know you have a form with at least 2 controls. What are the names of the
*controls*?

Do you have a text box named "date"?
Again, "Date" is a very bad name for a field of control. It is not very
descriptive.... date of What?? So you could have a *field* named date, a
control named *date* and there is a built in function named *date*. How
confusing...

In your DLOOKUP, you have "

/snip/ "date= " & Me.Date & " /snip/

Is Me.date the name of a control on the form? Or are you trying to get
today's date?


I made a table (SCAN) and entered some test data. I changed the field names
to differentiate the control names from the field names (and so I wouldn't be
as confused).

I made a form with three controls, a text box for a date, a text box for
idsurname and a button.

I tweeked the functions and got them to run without errors.

Your function: (watch for line wrap)

'---------------------------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

If IsNull(Me.tbIDsurname) Or IsNull(Me.[tbAttendDate]) Then
CheckDuplicates = False
Else
varDoseSupplied = DLookup("attendTime", "Scan", "[attenddate]= #" &
Me.[tbAttendDate] & "# And IDSurname = " & Me.tbIDsurname)
End If

If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
CheckDuplicates = True
Else
CheckDuplicates = False
End If

End Function
'------------------------------------

Mine: (watch for line wrap)
'------------------------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

' if date and IDsurname entered, lookup dose time
If Not IsNull(Me.tbIDsurname) Or Not IsNull(Me.[tbAttendDate]) Then
varDoseSupplied = DLookup("attendTime", "Scan", "[attenddate]= #" &
Me.[tbAttendDate] & "# And IDSurname = " & Me.tbIDsurname)
End If

CheckDuplicates = Not IsNull(varDoseSupplied)

' show message
If CheckDuplicates Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
End If

End Function
'------------------------------------


Another way would be to open a recordset based on the query for the subform
and check if the record count is GT 0. If the record count is GT 0 then
display a message that record(s) were found and the time of attendance.
The code would look something like:

(watch for line wrap)
'---------------------------
Public Sub CheckDuplicates()
Dim rs As DAO.Recordset
Dim strSQL As String
Dim varDoseSupplied As Variant

strSQL = "Select attendTime FROM SCAN"
strSQL = strSQL & " WHERE attendDate = #" & Me.[tbAttendDate] & "#"
strSQL = strSQL & " And SCAN.idsurname = " & Me.[tbIDsurname]
strSQL = strSQL & " ORDER BY SCAN.attendTime DESC , SCAN.attendDate DESC;"


Set rs = CurrentDb.OpenRecordset(strSQL)
If Not rs.EOF And Not rs.EOF Then
rs.MoveLast
rs.MoveFirst
varDoseSupplied = rs!attendTime
End If

If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
End If

rs.Close
Set rs = Nothing

End Sub
'---------------------------


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


srn said:
Thanks steve
I've tried the changes but still generating errors. Maybe i need to come at
this from a different angle.
I run a query of the scan table selecting records where date = date().
The results are then displayed on a subform/report.
Do you think i can look up this and compare IDSurname only, thus avoiding
the date issues?

:

PMFJI,

The syntax for the first IF() statement is wrong. You can't mix the single
line version of the IF() statement with the block form.

And like Arvin said, "Date" and 'Time " are reserved words in Access. For a
list of reserved words, see:

http://allenbrowne.com/AppIssueBadWord.html


I modified your code (for the first IF() statement):

(watch for line wrap!!!)
'------- beg code -------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

If IsNull(Me.IDSurname) Or IsNull(Me.[Date]) Then
CheckDuplicates = False
Else
varDoseSupplied = DLookup("Time", "Scan", "[date]= " & Me.[Date] & ""
And IDSurname = " & me.idsurname")
End If

If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
CheckDuplicates = True
Else
CheckDuplicates = False
End If

End Function
'------- beg code -------------------



In trying to understand your code, I rewrote it. Maybe it will be helpful

(watch for line wrap!!!)
'---------- end code -------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

' if date and IDsurname entered, lookup dose time
If Not IsNull(Me.IDSurname) Or Not IsNull(Me.[Date]) Then
varDoseSupplied = DLookup("[Time]", "Scan", "[date]= " & Me.[Date] & ""
And IDSurname = " & me.idsurname")

End If

CheckDuplicates = Not IsNull(varDoseSupplied)

' show message
If CheckDuplicates Then

MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly

End If

End Function
'---------- end code -------------------


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

I have tried both of these but error 13 still is triggered. Any other ideas?

:

Two possible errors. Error 13 is a datatype mismatch and you'll need to
surround your value with # like

DLookup("Time", "Scan", "Time= #" & Me.[Date] & "#")

The other possible problem is that you are using Date, a reserved word, as a
control name (and probably a field name, as well). It is better to change
it, but if that's not possible, at least use:

Me.[Date]
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

My form records patient attendance, time of attendance, date of attendance
and a number. These are recorded onto an attendance table called SCAN.
The following code is called in the afterupdate of the number field.
I want it to check the scan table to highlight if this patient has already
attended today, and to return a message box informing the operator that
the
patient has attended and the time at which they attended. Some patients
may
attend more than once, so it is purely to highlight and inform the
operator.
A variety of errors have been generated however i have solved those and
now
i am recieving a run time error 13, at the "else varDose Supplied...."
line.
Help


Public Function CheckDuplicates()
Dim varDoseSupplied As Variant
If IsNull(Me.IDSurname) Or IsNull(Me.Date) Then CheckDuplicates = False _
Else varDoseSupplied = DLookup("Time", "Scan", "date= " & Me.Date & "" And
IDSurname = " & me.idsurname")
If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
 
S

srn

Hi steve sorry for delay
as you say work interferes etc.
I will try the code again - i think i will build a test form just for this
code. If that works then i'll rework the form around the test.
I'll come back soon.
Again thanks for your time.


Steve Sanford said:
Stuart,

Sorry its taken so long to get back to you... work interferes with fun (as
usual).

OK, as I understand your setup:

Table name: PatientDetails
==================
IDSurname - PK - autonumber or custom number
Surname - text
Address - text

Table name: SCAN
=============
IDScan - autonumber
IDSurname - FK to PatientDetails
Time - date/time (of dose)
Date - date/time (of dose)
Days - text (records the number of doses dispensed)

Main form: Scan
============
Recordsource - Unbound(??)

Controls on form: (all unbound??)
-------------------------------------
IDSurname - combobox - displays IDSurname, Surname and Address from the
Patient details table
Days - text box - records the number of doses dispensed
Time - text box - control source set to time
Date - text box - control source set to Date

subform: ScanDailyAttendance
============
Recordsource - (??)

Controls on subform:
------------------------
IDSurname
Surname
Date
Time
Days


On the main form, where are the controls places - in the header or in the
details section?

Can you add "IDSurname" to the WHERE clause of the subform query? then when
you select the Patient using the combo box on the mainform ("Scan"), the
subform would only show the doses for that day and patient.


I retested the functions "CheckDuplicates" (both of them) and they seem to
work. If the function "CheckDuplicates" is in a standard module, the name of
the module must not be the same as the function.

Have you stepped thru the code to see where the error occurs? What errors
are you getting?



###############
BTW, here are links to "Rearch and Replace" tools that find and rename
objects in the database:

Free
MDBSearch: http://www3.bc.sympatico.ca/starthere/findandreplace

$$
Find and Replace: http://www.rickworld.com
Speed Ferret: http://www.moshannon.com
Total Access Analyzer: http://www.fmsinc.com
###############



HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


srn said:
Hi Steve
Thanks for all the effort and help.

My table called scan has the following fields:
IDScan - autonumber
IDSurname - number - lookup of the Patient details table giving: IDSurname
(a pateint number), Surname (Patients surname) and Address (Patients Address)
Time - date/time
Date - date/time
Days - text


My form called Scan has the following:
IDSurname - combobox - displays IDSurname, Surname and Address from the
Patient details table
Days - text box - records the number of doses dispensed
Time - text box - control source set to time
Date - text box - control source set to Date

I have a Subform callled ScanDailyAttendance:
This is based on a query of the scan table. It displays IDSurname, Surname,
Date, Time and Days. The results displayed are where the scan table date =
todays date.


The me.date refers to the date displayed in the date text box on the form.

This is a large database with approx 300,000 scan records, 2000 patients
records, 45,000 prescription records. The databease has evolved as i have
required more info and funtionality. This is why naming conventions have been
confused.
Stuart



Steve Sanford said:
OK, I know you have a table named "SCAN".
What are the names of the *fields* for:

patient attendance
time of attendance
date of attendance
a number


I know you have a form with at least 2 controls. What are the names of the
*controls*?

Do you have a text box named "date"?
Again, "Date" is a very bad name for a field of control. It is not very
descriptive.... date of What?? So you could have a *field* named date, a
control named *date* and there is a built in function named *date*. How
confusing...

In your DLOOKUP, you have "

/snip/ "date= " & Me.Date & " /snip/

Is Me.date the name of a control on the form? Or are you trying to get
today's date?


I made a table (SCAN) and entered some test data. I changed the field names
to differentiate the control names from the field names (and so I wouldn't be
as confused).

I made a form with three controls, a text box for a date, a text box for
idsurname and a button.

I tweeked the functions and got them to run without errors.

Your function: (watch for line wrap)

'---------------------------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

If IsNull(Me.tbIDsurname) Or IsNull(Me.[tbAttendDate]) Then
CheckDuplicates = False
Else
varDoseSupplied = DLookup("attendTime", "Scan", "[attenddate]= #" &
Me.[tbAttendDate] & "# And IDSurname = " & Me.tbIDsurname)
End If

If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
CheckDuplicates = True
Else
CheckDuplicates = False
End If

End Function
'------------------------------------

Mine: (watch for line wrap)
'------------------------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

' if date and IDsurname entered, lookup dose time
If Not IsNull(Me.tbIDsurname) Or Not IsNull(Me.[tbAttendDate]) Then
varDoseSupplied = DLookup("attendTime", "Scan", "[attenddate]= #" &
Me.[tbAttendDate] & "# And IDSurname = " & Me.tbIDsurname)
End If

CheckDuplicates = Not IsNull(varDoseSupplied)

' show message
If CheckDuplicates Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
End If

End Function
'------------------------------------


Another way would be to open a recordset based on the query for the subform
and check if the record count is GT 0. If the record count is GT 0 then
display a message that record(s) were found and the time of attendance.
The code would look something like:

(watch for line wrap)
'---------------------------
Public Sub CheckDuplicates()
Dim rs As DAO.Recordset
Dim strSQL As String
Dim varDoseSupplied As Variant

strSQL = "Select attendTime FROM SCAN"
strSQL = strSQL & " WHERE attendDate = #" & Me.[tbAttendDate] & "#"
strSQL = strSQL & " And SCAN.idsurname = " & Me.[tbIDsurname]
strSQL = strSQL & " ORDER BY SCAN.attendTime DESC , SCAN.attendDate DESC;"


Set rs = CurrentDb.OpenRecordset(strSQL)
If Not rs.EOF And Not rs.EOF Then
rs.MoveLast
rs.MoveFirst
varDoseSupplied = rs!attendTime
End If

If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
End If

rs.Close
Set rs = Nothing

End Sub
'---------------------------


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

Thanks steve
I've tried the changes but still generating errors. Maybe i need to come at
this from a different angle.
I run a query of the scan table selecting records where date = date().
The results are then displayed on a subform/report.
Do you think i can look up this and compare IDSurname only, thus avoiding
the date issues?

:

PMFJI,

The syntax for the first IF() statement is wrong. You can't mix the single
line version of the IF() statement with the block form.

And like Arvin said, "Date" and 'Time " are reserved words in Access. For a
list of reserved words, see:

http://allenbrowne.com/AppIssueBadWord.html


I modified your code (for the first IF() statement):

(watch for line wrap!!!)
'------- beg code -------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

If IsNull(Me.IDSurname) Or IsNull(Me.[Date]) Then
CheckDuplicates = False
Else
varDoseSupplied = DLookup("Time", "Scan", "[date]= " & Me.[Date] & ""
And IDSurname = " & me.idsurname")
End If

If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
CheckDuplicates = True
Else
CheckDuplicates = False
End If

End Function
'------- beg code -------------------
 
S

srn

Steve
Thanks for all the help. I followed your advice and ended up re-writing the
entire database, removed all dubious names etc. The Dlookup function works
just as i had wanted. It is called when then final text box has lost focus,
prior to the Save button.
Stuart


Steve Sanford said:
Stuart,

Sorry its taken so long to get back to you... work interferes with fun (as
usual).

OK, as I understand your setup:

Table name: PatientDetails
==================
IDSurname - PK - autonumber or custom number
Surname - text
Address - text

Table name: SCAN
=============
IDScan - autonumber
IDSurname - FK to PatientDetails
Time - date/time (of dose)
Date - date/time (of dose)
Days - text (records the number of doses dispensed)

Main form: Scan
============
Recordsource - Unbound(??)

Controls on form: (all unbound??)
-------------------------------------
IDSurname - combobox - displays IDSurname, Surname and Address from the
Patient details table
Days - text box - records the number of doses dispensed
Time - text box - control source set to time
Date - text box - control source set to Date

subform: ScanDailyAttendance
============
Recordsource - (??)

Controls on subform:
------------------------
IDSurname
Surname
Date
Time
Days


On the main form, where are the controls places - in the header or in the
details section?

Can you add "IDSurname" to the WHERE clause of the subform query? then when
you select the Patient using the combo box on the mainform ("Scan"), the
subform would only show the doses for that day and patient.


I retested the functions "CheckDuplicates" (both of them) and they seem to
work. If the function "CheckDuplicates" is in a standard module, the name of
the module must not be the same as the function.

Have you stepped thru the code to see where the error occurs? What errors
are you getting?



###############
BTW, here are links to "Rearch and Replace" tools that find and rename
objects in the database:

Free
MDBSearch: http://www3.bc.sympatico.ca/starthere/findandreplace

$$
Find and Replace: http://www.rickworld.com
Speed Ferret: http://www.moshannon.com
Total Access Analyzer: http://www.fmsinc.com
###############



HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


srn said:
Hi Steve
Thanks for all the effort and help.

My table called scan has the following fields:
IDScan - autonumber
IDSurname - number - lookup of the Patient details table giving: IDSurname
(a pateint number), Surname (Patients surname) and Address (Patients Address)
Time - date/time
Date - date/time
Days - text


My form called Scan has the following:
IDSurname - combobox - displays IDSurname, Surname and Address from the
Patient details table
Days - text box - records the number of doses dispensed
Time - text box - control source set to time
Date - text box - control source set to Date

I have a Subform callled ScanDailyAttendance:
This is based on a query of the scan table. It displays IDSurname, Surname,
Date, Time and Days. The results displayed are where the scan table date =
todays date.


The me.date refers to the date displayed in the date text box on the form.

This is a large database with approx 300,000 scan records, 2000 patients
records, 45,000 prescription records. The databease has evolved as i have
required more info and funtionality. This is why naming conventions have been
confused.
Stuart



Steve Sanford said:
OK, I know you have a table named "SCAN".
What are the names of the *fields* for:

patient attendance
time of attendance
date of attendance
a number


I know you have a form with at least 2 controls. What are the names of the
*controls*?

Do you have a text box named "date"?
Again, "Date" is a very bad name for a field of control. It is not very
descriptive.... date of What?? So you could have a *field* named date, a
control named *date* and there is a built in function named *date*. How
confusing...

In your DLOOKUP, you have "

/snip/ "date= " & Me.Date & " /snip/

Is Me.date the name of a control on the form? Or are you trying to get
today's date?


I made a table (SCAN) and entered some test data. I changed the field names
to differentiate the control names from the field names (and so I wouldn't be
as confused).

I made a form with three controls, a text box for a date, a text box for
idsurname and a button.

I tweeked the functions and got them to run without errors.

Your function: (watch for line wrap)

'---------------------------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

If IsNull(Me.tbIDsurname) Or IsNull(Me.[tbAttendDate]) Then
CheckDuplicates = False
Else
varDoseSupplied = DLookup("attendTime", "Scan", "[attenddate]= #" &
Me.[tbAttendDate] & "# And IDSurname = " & Me.tbIDsurname)
End If

If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
CheckDuplicates = True
Else
CheckDuplicates = False
End If

End Function
'------------------------------------

Mine: (watch for line wrap)
'------------------------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

' if date and IDsurname entered, lookup dose time
If Not IsNull(Me.tbIDsurname) Or Not IsNull(Me.[tbAttendDate]) Then
varDoseSupplied = DLookup("attendTime", "Scan", "[attenddate]= #" &
Me.[tbAttendDate] & "# And IDSurname = " & Me.tbIDsurname)
End If

CheckDuplicates = Not IsNull(varDoseSupplied)

' show message
If CheckDuplicates Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
End If

End Function
'------------------------------------


Another way would be to open a recordset based on the query for the subform
and check if the record count is GT 0. If the record count is GT 0 then
display a message that record(s) were found and the time of attendance.
The code would look something like:

(watch for line wrap)
'---------------------------
Public Sub CheckDuplicates()
Dim rs As DAO.Recordset
Dim strSQL As String
Dim varDoseSupplied As Variant

strSQL = "Select attendTime FROM SCAN"
strSQL = strSQL & " WHERE attendDate = #" & Me.[tbAttendDate] & "#"
strSQL = strSQL & " And SCAN.idsurname = " & Me.[tbIDsurname]
strSQL = strSQL & " ORDER BY SCAN.attendTime DESC , SCAN.attendDate DESC;"


Set rs = CurrentDb.OpenRecordset(strSQL)
If Not rs.EOF And Not rs.EOF Then
rs.MoveLast
rs.MoveFirst
varDoseSupplied = rs!attendTime
End If

If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
End If

rs.Close
Set rs = Nothing

End Sub
'---------------------------


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

Thanks steve
I've tried the changes but still generating errors. Maybe i need to come at
this from a different angle.
I run a query of the scan table selecting records where date = date().
The results are then displayed on a subform/report.
Do you think i can look up this and compare IDSurname only, thus avoiding
the date issues?

:

PMFJI,

The syntax for the first IF() statement is wrong. You can't mix the single
line version of the IF() statement with the block form.

And like Arvin said, "Date" and 'Time " are reserved words in Access. For a
list of reserved words, see:

http://allenbrowne.com/AppIssueBadWord.html


I modified your code (for the first IF() statement):

(watch for line wrap!!!)
'------- beg code -------------------
Public Function CheckDuplicates()
Dim varDoseSupplied As Variant

If IsNull(Me.IDSurname) Or IsNull(Me.[Date]) Then
CheckDuplicates = False
Else
varDoseSupplied = DLookup("Time", "Scan", "[date]= " & Me.[Date] & ""
And IDSurname = " & me.idsurname")
End If

If Not IsNull(varDoseSupplied) Then
MsgBox "This dose has already been dispensed today at " &
Format(varDoseSupplied, "hh,mm,ss"), vbOKOnly
CheckDuplicates = True
Else
CheckDuplicates = False
End If

End Function
'------- beg code -------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top