error trapping

M

Mark

Hi all,

Hoping someone can help me with an error trapping routine for the following
situation:

I have a 1:many relationship between Table1 and Table2.
I have a mainform based on Table1 and a subform based on Table2.

Table1 has a primary key: NameID
Table2 contains a primary key based upon two fields: NameID and
ProblemNumber.

I would like to trap two errors and provide custom messages:

1. When the user begins to fill out fields in the subform before entering
data into the mainform -- i.e., in the case where no Table1 record has yet
been created.

2. When the user enters the same ProblemNumber twice for the same client,
then I would like to generate a custom message when the user attempts to
leave the ProblemNumber field which contains the duplicate value.

Thanks for any help,
Mark
 
P

Piet Linden

Hi all,

Hoping someone can help me with an error trapping routine for the following
situation:

I have a 1:many relationship between Table1 and Table2.
I have a mainform based on Table1 and a subform based on Table2.

Table1 has a primary key: NameID
Table2 contains a primary key based upon two fields: NameID and
ProblemNumber.

I would like to trap two errors and provide custom messages:

1. When the user begins to fill out fields in the subform before entering
data into the mainform -- i.e., in the case where no Table1 record has yet
been created.

2. When the user enters the same ProblemNumber twice for the same client,
then I would like to generate a custom message when the user attempts to
leave the ProblemNumber field which contains the duplicate value.

Thanks for any help,
Mark

for #1, one option is to simply disable the subform until all the
fields in the main form are filled in.
#2 - you can use DCount() to return a count of existing records
matching your criteria. If it's >0, then stop the insert. (Set
Cancel=True)
 
M

Mark

Thanks, Piet

I was thinking there was a way to trap the error numbers for both of these
situations, but your way works just as well, I think.

Enabling/Disabling the subform works, but the user has to figure out why
there's no response when they click a field on the subform. The DCount
solution for #2, however, gives me the idea for #1 of looking for a null
value in one of the fields for the mainform and then using Cancel = True for
the subform if that mainform field is null, and then supplying a message.
Thanks for the suggestions,
Mark

Hi all,

Hoping someone can help me with an error trapping routine for the following
situation:

I have a 1:many relationship between Table1 and Table2.
I have a mainform based on Table1 and a subform based on Table2.

Table1 has a primary key: NameID
Table2 contains a primary key based upon two fields: NameID and
ProblemNumber.

I would like to trap two errors and provide custom messages:

1. When the user begins to fill out fields in the subform before entering
data into the mainform -- i.e., in the case where no Table1 record has yet
been created.

2. When the user enters the same ProblemNumber twice for the same client,
then I would like to generate a custom message when the user attempts to
leave the ProblemNumber field which contains the duplicate value.

Thanks for any help,
Mark

for #1, one option is to simply disable the subform until all the
fields in the main form are filled in.
#2 - you can use DCount() to return a count of existing records
matching your criteria. If it's >0, then stop the insert. (Set
Cancel=True)
 
F

FPS, Romney

Thank you, AccessVandal, much appreciated.
Mark

AccessVandal via AccessMonster.com said:
Disabling the subform is a good choice.

If disabling is not an option, you can use the form's BeforeInsert event to
trigger a message and warn the user. Something like....

Private Sub Form_BeforeInsert(Cancel As Integer)
If IsNull(Forms!YourMainForm!YourControlName) Then
MsgBox "No ID created. Need the NameID"
Cancel = True
Forms!YourMainForm!YourControlName.SetFocus
Else
'do nothing
End If
End Sub
 

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