The SQL is:
SELECT tblTires.TireID, tblTires.Brand, tblTires.Model,
tblTires.[DOT#],
tblTires.SerialNumber
FROM tblTires
WHERE (((tblTires.Brand)=[forms]![frmEnterTires]![cboBrand]) AND
((tblTires.Model)=[forms]![frmEnterTires]![cboModel]) AND
((tblTires.[DOT#])=[forms]![frmEnterTires]![ctlDOT_]) AND
((tblTires.SerialNumber)=[forms]![frmEnterTires]![ctlSerialNumber])) OR
(((tblTires.Brand)=[forms]![frmEnterTires]![cboBrand]) AND
((tblTires.Model)=[forms]![frmEnterTires]![cboModel]) AND
((tblTires.[DOT#])=[forms]![frmEnterTires]![ctlDOT_]) AND
((tblTires.SerialNumber) Is Null)) OR
(((tblTires.Brand)=[forms]![frmEnterTires]![cboBrand]) AND
((tblTires.Model)=[forms]![frmEnterTires]![cboModel]) AND
((tblTires.[DOT#])
Is Null) AND
((tblTires.SerialNumber)=[forms]![frmEnterTires]![ctlSerialNumber]));
The code in the form is:
Private Sub DuplicateEntry()
Dim intTire As Integer
Dim varBrand, varModel, varDot, varSN
Dim Msg, Style, Title, Response, MyString
intTire = Nz(DLookup("TireID", "qryDuplicateTire"), 0)
varBrand = DLookup("Brand", "qryDuplicateTire")
varModel = DLookup("Model", "qryDuplicateTire")
varDot = DLookup("[DOT#]", "qryDuplicateTire")
varSN = DLookup("SerialNumber", "qryDuplicateTire")
Msg = _
"Tire " & intTire & vbCrLf & _
"" & varBrand & """ "" & varModel & """ & vbCrLf & _
"DOT Number "" & varDOT & """ & " " & "Serial Number "" &
varSN
& """ & vbCrLf & _
"has already been entered. Click OK to modify information "
&
vbCrLf & _
"or CANCEL to abort entry."
Style = vbOKCancel
Title = "Duplicate Entry!"
If intTire <> 0 Then
Response = MsgBox(Msg, Style, Title)
If Response = vbOK Then ' User chose OK.
MyString = "OK" ' Perform some action.
Me.ctlDOT_.Undo
Me.ctlSerialNumber.Undo
Me.ctlDOT_.SetFocus
Else ' User chose No.
MyString = "Cancel" ' Perform some action.
Me.cboBrand.Undo
Me.cboModel.Undo
Me.ctlDOT_.Undo
Me.ctlSerialNumber.Undo
Me.cboBrand.SetFocus
End If
This is called from ctlSerialNumber BeforeUpdate and on Exit in case of
no
entry in this control.
BTW: I have another DLookup on another query that was working fine a
couple
days ago that now is giving me an "Object doesn't contain the
automation
object TireID" error. The TireID is in the query.
--
Thanks for your help!
Walter
:
Please post the code that you're running; let's see what it contains.
Likely
we will be able to see the problem then.
--
Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
All of the criteria are included in the query itself. The value
being
looked
up is integer, all criteria are text. I have:
intMyVariable = NZ(DLookup("TableID", "qryTableLookup"),0)
--
Thanks for your help!
Walter
:
Then I'm guessing that you're not delimiting the value from
myControl
with '
characters, which is needed for string values. This is example of
how
you'd
do it in VBA code, if that is what you're using:
Dim strValue As String
strValue = DLookup("FieldBeingLookedUp", _
"TableQueryOfData", _
"FieldBeingSearched='" & Me.myControl.Value & "'")
--
Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
All 4 are text.
--
Thanks for your help!
Walter
:
What type of data are in the myControl control -- number?
string/text?
date?
--
Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
No. It is a stand alone form.
--
Thanks for your help!
Walter
:
Is the myControl control in a subform on that form?
--
Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
Yes. There are 4 controls on the form. 2 will have data
and
at
least
1
of
the other 2 will have data. The form contains the same
data
as I
supplied
to
the query to open it independantly.
--
Thanks for your help!
Walter
:
Is there a value in the myControl control on that form?
--
Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
message
I have a query to prevent duplicate entries which is
called
from a
form.
The
criteria are set to forms!myForm!myControl. When I open
the
query
and
supply
the criteria, it works but when it is opened from the
form
there
are
no
records displayed.