So, if you don't want to use DLookup, you could "roll your own" creation
of a recordset that consisted only of the rowID, then test the number of
records returned. I haven't tested this approach vs. the DLookup, so I
don't know which would be faster.
So you figure your users would know/remember an ID-number better than a
person's name, or ...?
Regards
Jeff Boyce
Microsoft Office/Access MVP
Thanks for your reponse. I'll make myself clearer.
In a form I've made a 'quick-search' field where users can enter an
ID-number and press enter, to save them from having to use Ctrl-F all
the time. Before really locating the value I want to make sure the
record is there. I found that Dlookup is more code efficient than a
recordset. The code is working well but I'd like to know if I can make
it better.
Private Sub fldQS_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
Me.Refresh 'make sure the entered value is stored so it can be
processed
If IsNumeric(fldQS) And fldQS > 0 Then
If IsNull(DLookup("[ID]", "Addresses", "[ID_address] = " & fldQS
& "")) Then
MsgBox "ID-number " & fldQS & " not found."
Else
Me.Recordset.FindFirst "ID_address = " & fldQS
End If
Else
MsgBox "Make sure to enter a positive number."
End If
fldQS = Null
End If
End Sub
John
"Jeff Boyce" <
[email protected]> schreef in bericht
John
You've asked a very specific "how to" question.
Now let me ask "why?" As in "why do you want to know if the record
already exists?" What business need are you satisfying for you
user(s) by looking for an existing record (by RecordID, yet?!)?
I don't have enough information to tell, but it sounds like there's a
chance you could be using a combobox to let the user look up existing
records...
Regards
Jeff Boyce
Microsoft Office/Access MVP
To check if a record with a certain ID_number is there I now use:
If IsNull(DLookup("[ID_number]", "Adressen", "[ID_number] = " & fldQS
& "")) Then
Since I'm not really using dlookup here for what it is meant for, is
there a better (shorter) way to do this?
Thanks,
John