DLookup Question

B

Bonnie

Hi there folks! Using A02 on XP. Need to cancel the
addition of a record (Cancel=True in BeforeInsert event)
if the fields [GPNum] and [CkNum] duplicate a record that
already exists when adding a record on my form.

DLookup sounds like what I want, just haven't used it
before, especially with 2 fields. Or do I need to create a
query field that combines the fields into 1 and do the
lookup on the 1 query field?

Not sure of the wordage and would really appreciate any
help or advice. Thanks in advance for your time.
 
R

Rick Brandt

Bonnie said:
Hi there folks! Using A02 on XP. Need to cancel the
addition of a record (Cancel=True in BeforeInsert event)
if the fields [GPNum] and [CkNum] duplicate a record that
already exists when adding a record on my form.

BeforeInsert occurs on the first keystroke in a new record so I don't think
it will work for you. You should be able to use BeforeUpdate instead.
DLookup sounds like what I want, just haven't used it
before, especially with 2 fields. Or do I need to create a
query field that combines the fields into 1 and do the
lookup on the 1 query field?

Not sure of the wordage and would really appreciate any
help or advice. Thanks in advance for your time.

DLookup("SomeField" , "SomeTable", "SomeTextField = 'Text' AND
SomeNumberField = 123")

You can have as many ANDs and ORs in a DLookup as you can have in a query.
 
B

Bonnie

Thank you VERY much! Truly appreciate the advice and info.
I'll try it in the morning...can't wait! I think I can do
it with one field but will try to use the AND to add my
second field. Thank you for taking the time to help others.
-----Original Message-----
Hi there folks! Using A02 on XP. Need to cancel the
addition of a record (Cancel=True in BeforeInsert event)
if the fields [GPNum] and [CkNum] duplicate a record that
already exists when adding a record on my form.

BeforeInsert occurs on the first keystroke in a new record so I don't think
it will work for you. You should be able to use BeforeUpdate instead.
DLookup sounds like what I want, just haven't used it
before, especially with 2 fields. Or do I need to create a
query field that combines the fields into 1 and do the
lookup on the 1 query field?

Not sure of the wordage and would really appreciate any
help or advice. Thanks in advance for your time.

DLookup("SomeField" , "SomeTable", "SomeTextField = 'Text' AND
SomeNumberField = 123")

You can have as many ANDs and ORs in a DLookup as you can have in a query.


--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com


.
 

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