The code module is the code associated with the form. If you open the
form
in design view and click View >> Code you the VBA editor will open. On
the
right is the code, starting (probably) with Option Compare Database at
the
top. Press Ctrl + R to be sure the Project Explorer is open on the left.
It
should show the form name highlighted. All of what you see in the
right-hand
pane is the form's code module. You can think of it as the code library
for
the form.
If you understand the After Update event you may already have seen the
form's
code module. The code Klatuu provided goes into the code module. Use
your
actual control names in place of txtSono and txtLineNo as needed. The
code
(a user-defined function) could go anywhere in the module other than
inside
another procedure. To run the code, open the form's property sheet.
Click
the event tab, and type =FindNumber() directly on the property sheet at
the
After Update event.
I would use Klatuu's method with the RecordsetClone. I would have a
difficult time explaining just why, but if you are interested you could
post
a new thread asking about the difference. There are people who could
explain
it easily. Regarding your DLookup, there is an extra quote:
And "[lineno]=
should be
And [lineno]=
The DLookup assumes Lineno and Sono are text fields.
Darrell said:
I AM talking about locating an existing record and adding the value of
the "Number" field to the form (table, actually).
I don't know where to put the code you gave me, can you please explain
what you mean by the "form's code module"? I do understand the
AfterUpdate event.
In the meantime, I have tried experimenting with the DLookup function,
which almost works. Here's what I have entered in the AfterUpdate event
Private Sub lineno_AfterUpdate()
Number = DLookup("[Number]", "tblSO_Items", "[sono]='" &
Forms![sbfProgressReport]![sono] & "'" And "[lineno]='" &
Forms![sbfProgressReport]![lineno] & "'")
End Sub
It gives me a Run-time error '13':
Type mismatch
If I enter criteria manually in the AfterUpdate, such as
Number = DLookup("[Number]", "tblSO_Items", "[sono]='81517' And
[lineno]='3'")
then it works great.
If you are talking about locating an existing record, you can do that
using the After Update events of sono and lineno. You have to include
both so you
[quoted text clipped - 31 lines]
the Number. Is this possible? Thanks,
Darrell