Sometimes the newsreader will introduce spurious characters.
Try typing the code in. If that still fails, copy and paste what is failing
and post that.
AND SOMETIMES I make an error like including an extra quote mark at the end
IF DCount("*","[T
roduction Data]", _
"[Date] = #" & TheDate & "# AND" _
& " Shift = " & PartShift & " AND" _
& " PartID = " & cboPartID & " AND" _
& " McnID = " & cboMcnID ) >0 Then
Check_For_Duplicate_Records = "YES"
Else
Check_For_Duplicate_Records = "NO"
End If
I did assume that
-- [Date] is a date field
-- Shift is a number field
-- PartID is a number field
-- McnID is a number field
If any of those are incorrect, you will get an error.
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Bob Barnes wrote:
Thank you John - I pated the code in and there's something wrong w/ the
synatax...although I don't see a syntax error..it turns red..
:
I duplicated your code and I did not see the same problem. I got the expected
results. I am using Access 2003 SP2
You might try using the recordset's record count *Rs.RecordCount > 0) or
using the DCount function instead. In this case, DCount should be simpler to
implement and I suspect that it will be just as fast (at least from a user's
perspective of the elapsed time).
IF DCount("*","[T
roduction Data]", _
"[Date] = #" & TheDate & "# AND" _
& " Shift = " & PartShift & " AND" _
& " PartID = " & cboPartID & " AND" _
& " McnID = " & cboMcnID ") >0 Then
Check_For_Duplicate_Records = "YES"
Else
Check_For_Duplicate_Records = "NO"
End If
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Bob Barnes wrote:
David - Thank you.
I've opened the recordset 2 ways...thru VBA code, and then making it a Query
& manually running the Query. In both instances, I see the "Blank Record"...
Here's concise VBA code which opens the "Blank Record", even though it
doesn't exist..here running a Function "Check_For_Duplicate_Records"
Dim Z As Database, RS As DAO.Recordset, Q$
'Query DB to see if DupRec for Date, Shift, Part & Mcn
'for data being entered = 4-Field PK.
Set Z = CurrentDb
Q = "SELECT DISTINCTROW [Date], Shift, PartID, McnID " _
& "From [T
roduction Data]" _
& " WHERE (([Date] = #" & TheDate & "#) AND" _
& " (Shift = " & PartShift & ") AND" _
& " (PartID = " & cboPartID & ") AND" _
& " (McnID = " & cboMcnID & "));"
Set RS = Z.OpenRecordset(Q, dbOpenSnapshot)
With RS
If Not .BOF And Not .EOF Then
'now you know you have a minimum of one record
Check_For_Duplicate_Records = "YES"
Else
Check_For_Duplicate_Records = "NO"
End If
.Close: Set RS = Nothing: Z.Close: Set Z = Nothing
End With
It results in...
Check_For_Duplicate_Records = "YES"
Ideas? TIA - Bob
:
How are you doing that? When I open a query like
that in Access, I always get a blank line. It's the blank
line for entering data.
You get the blank line if you open the recordset that way.
So how are you opening the recordset?
Also,
BOF and EOF may not be valid unless you have done a
MoveFirst/MoveLast.
There is an implicit MoveFirst when you do a requery.
In some rare situations, there is not an implicit MoveFirst,
even though the situation is almost the same as all the other
things you have done, where there was an implicit MoveFirst.
So how are you opening the recordset?
(david)
An example SQL..
SELECT ProdData.Date, ProdData.Shift, ProdData.PartID, ProdData.McnID
FROM ProdData
WHERE (((ProdData.Date)=#5/31/2009#) AND ((ProdData.Shift)=1) AND ((Prod
Data.PartID)=475) AND ((ProdData.McnID)=163));
The above Record does NOT exist, but returns a "Blank Row" (a Single
Record)
w/ what looks like Nulls (but testing for Len of those Fields > 0, or
IsNull
doesn't work)..it returns a "Record".
I've inherited this DB, and perhaps the Field "Date" is causing a problem
??
Even tried...
with rst
if not .bof and not .eof then
now you know you have a minimum of one record
else
no records so do something here...
end if
end with
..but that returns a "Record"...even though it shouldn't??
Ideas? TIA - Bob