Validation before focus enters subform

swee

Registered User.
Local time
Today, 07:44
Joined
Aug 11, 2004
Messages
66
When I click on my subform after entering some data in the primary form, I get this error message:

"The Microsoft Jet database engine can't find a record in the table <name> with key matching field(s) <name>. (Error 3101)"

This is because I have not filled in a ItemCode, a combobox, on the parent form and ItemCode is part of a one-to-many relationship that involves automatic filling in of other fields such as ItemDesc, UnitPrice, etc. How do I code the validation that handles such an error?



Thanks in advance,

Swee
 
Try using this on the onExit of you Item Code

if isnull(me.itemcode) or me.itemCode = "" then
Msgbox "Your Message",vbokonly,"YourTitle"
me.itemcode.setfocus
else
me.NextField.setfocus
endif
end

this will make sure that your itemcode is filled or not , if you are using no item code then make the default value as "N/A" (Not Available). this will place N/A as the default value of you itemcode.
 
I've added the code in the onExit event of ItemCode but it doesn't solve the problem. After filling in some fields on the parent form, I click on the subform and I get the same error. I tried adding the code to the onEnter event of the subform as well but it doesn't work too.

The reason this happens is because the ItemCode is a field that automatically fills up other fields when it has been selected. Thus when I leave it blank and try to enter the subform, it comes up with an error that says it can't find a record in the table with key matching field.

How do I get rid of the error message?
 
Hi,

I've attached a small db for you guys to experiment with and hopefully, understand my problem better.

1. Open FrmOrderInfoMain
2. Choose an outlet from the Brand combobox.
3. Click on the subform. At this point, you will get an error message.

Grateful and appreciative of any input. Thanks!
 

Attachments

OK,
I think that you will have to use the before update event of the form and the built in cancel of this event.

I have put it into your example for you to have a look at.

Steve
 

Attachments

Thanks Steve! You just helped me sleep better tonight :D That had been bugging me for days and I've been trying all sorts of methods but to no avail.
 

Users who are viewing this thread

Back
Top Bottom