problem with automatically filling in field

  • Thread starter Thread starter Fao, Sean
  • Start date Start date
F

Fao, Sean

Hello All,

I have a form with a field that I would like to get filled in automatically
with the same value as another field on the table. These two fields are
linked through a relationship. What I have done to have the value filled in
automatically is place the following code on the "On Lost Focus" event of
one of the two related fields:

<CODE_SNIP>
[Forms]![frmQuoteMaster]![tblQuoteDetail Subform].Form![QuoteNumber] =
QuoteNumber
</CODE_SNIP>

This works, however I get this error message (I'm guessing before my code
has a chance to run) "You cannot add or change a record because a related
record is required in table 'tblQuoteMaster'." After I click 'Ok', my code
is run and the value is filled in properly.

Is this just Access warning me of the relationship between the two fields?
If so, is there any way I can ignore it since I'm correcting the error as
soon as it's done checking. I've tried adding an "On Error Resume Next" to
my code to no avail.

Quite honestly, I'm not sure why I need to have the value filled in anyway.
I was under the impression that the relationship would cause the value to be
automatically filled in without the need of code. If that were the case, I
apparently have something else wrong.

I appreciate any advice and thank you all in advance,

Sean
 
You're right. You can have the information filled in
automatically without codes. First both the primary
table and the foreign table should have the same field
names for those fields you want automatically filled in.
Next, create a query for the foreign form/table and add
to the design grid the field(s) that you want
automatically filled in from the primary table, except
for the linked field which should be added to the grid
from the foreign table. When you enter the value in the
linked field of the foreign table, the rest of the
matching fields will automatically be filled in from the
primary table. Good luck!
-----Original Message-----
Hello All,

I have a form with a field that I would like to get filled in automatically
with the same value as another field on the table. These two fields are
linked through a relationship. What I have done to have the value filled in
automatically is place the following code on the "On Lost Focus" event of
one of the two related fields:

<CODE_SNIP>
[Forms]![frmQuoteMaster]![tblQuoteDetail Subform].Form! [QuoteNumber] =
QuoteNumber
</CODE_SNIP>

This works, however I get this error message (I'm guessing before my code
has a chance to run) "You cannot add or change a record because a related
record is required in table 'tblQuoteMaster'." After I click 'Ok', my code
is run and the value is filled in properly.

Is this just Access warning me of the relationship between the two fields?
If so, is there any way I can ignore it since I'm correcting the error as
soon as it's done checking. I've tried adding an "On Error Resume Next" to
my code to no avail.

Quite honestly, I'm not sure why I need to have the value filled in anyway.
I was under the impression that the relationship would cause the value to be
automatically filled in without the need of code. If that were the case, I
apparently have something else wrong.

I appreciate any advice and thank you all in advance,

Sean



.
 
Back
Top