Replace error message

G

Guest

Hello.
I have a table «Customers» linked to a table «Zip Codes». The idea is that
when I enter a zip code in the Customers form, it gives me the respective
city from de «Zip Codes» table.
When I add a new record to the Customers table, and if I close the form
before entering a zip code it gives me an error saying something like «It was
not possible to find a match zip code from the «Zip Code» table» and «The
form cannot be saved this time». I know why this happens: the «Zip Code»
table doesn't have a blank zip code, but my question is:
What is the best way to avoid this error? Or to replace this Access message
to another one more user friendly?
I know that a possible answer to this, is to predefine a valid zip code in
the Customer form field, but is this the only way?
Someone can help me, please?
Thank you in advance.
Best regards.
 
C

Carl Rapson

acores said:
Hello.
I have a table «Customers» linked to a table «Zip Codes». The idea is that
when I enter a zip code in the Customers form, it gives me the respective
city from de «Zip Codes» table.
When I add a new record to the Customers table, and if I close the form
before entering a zip code it gives me an error saying something like «It
was
not possible to find a match zip code from the «Zip Code» table» and «The
form cannot be saved this time». I know why this happens: the «Zip Code»
table doesn't have a blank zip code, but my question is:
What is the best way to avoid this error? Or to replace this Access
message
to another one more user friendly?
I know that a possible answer to this, is to predefine a valid zip code in
the Customer form field, but is this the only way?
Someone can help me, please?
Thank you in advance.
Best regards.

If you've defined a relationship between the two tables based on the zip
code, it may not be possible to save a customer record without a valid zip
code entered (I say "may not" because I don't use the Relationships window
much, so I don't know for sure). What I would suggest is to remove the
relationship (if there is one) and handle it all through code. Use a combo
box on the Customers form to select the zip code, and in the form's Load
event populate the combo box from the Zip Code table (zip code in the first
column and city in the second column). In the AfterUpdate event of the combo
box, reference the second column of the combo box to put the city into the
city field on your form:

me.txtCity = cboZipCodes.Column(1)

If you want to always require a zip code to be entered, then test for it in
the form's BeforeInsert event. You can cancel that event if the zip code
field is empty, which will prevent the record from being inserted (thus not
running afoul of the relationship).

Carl Rapson
 

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

Similar Threads


Top