Run time error 3101 - Error handling code (1 Viewer)

djossh

Registered User.
Local time
Today, 04:27
Joined
Oct 19, 2011
Messages
89
Hi I need some help on error handling...I got an error of 3101.. and I know the reason for this error is that, I dont have record ID in my table.... are there any code to handle this?? I want the user to get prompt by a message box that the ID he/she is trying to enter is not yet in the table.... thanks....
 

RainLover

VIP From a land downunder
Local time
Today, 11:27
Joined
Jan 5, 2009
Messages
5,041
Hi I need some help on error handling...I got an error of 3101.. and I know the reason for this error is that, I dont have record ID in my table.... are there any code to handle this?? I want the user to get prompt by a message box that the ID he/she is trying to enter is not yet in the table.... thanks....

Your problem is not handling the error but in your design.

The error should never happen in the first place.

IDs happen in the background and should be created automatically.

They should never be seen by the end user and no code should be required.

Perhaps your problem is with your relationships.

I have never seen this problem in a properly constructed Database.
 

djossh

Registered User.
Local time
Today, 04:27
Joined
Oct 19, 2011
Messages
89
Your problem is not handling the error but in your design.

The error should never happen in the first place.

IDs happen in the background and should be created automatically.

They should never be seen by the end user and no code should be required.

Perhaps your problem is with your relationships.

I have never seen this problem in a properly constructed Database.

The field in the form Im referring to is The "Employee Number" it so happened that employee number is my ID number also.. The form has a subform where I can edit/delete some information.. I intentionally type ID that are not in the table because the user might do the same.. any better suggestions?? thanks for the reply..
 

bob fitz

AWF VIP
Local time
Today, 02:27
Joined
May 23, 2011
Messages
4,721
Why not use a combo box populated with the employees and set it's Limit to list property to true.
 

djossh

Registered User.
Local time
Today, 04:27
Joined
Oct 19, 2011
Messages
89
Why not use a combo box populated with the employees and set it's Limit to list property to true.

I have 600 employees.. I think if I use a combo box it will take me sometimes to scroll to the bottom, though you have a point in setting property on it... i'll try that.. thanks..
 

RainLover

VIP From a land downunder
Local time
Today, 11:27
Joined
Jan 5, 2009
Messages
5,041
We can come back to the ID later if you wish. For now I will simply say that using Autonumber is a better method.

I would think that as I suggested before that you have a problem with your Relationships.

Your Sub Form is Joined to the Main form and should be linked via the Employee ID. If you have done this correctly then the sub form will only show records with the same ID as in the Main Form. Make sure you have also set Referential Intregity in the Database window as well.

Once you start entering information into a new Record in the Sub Form the ID will auto populate.

As I said "No need for code"

The use of a Combo box would be good in the Main Form for searching. You can set this to limit to list. There is also code about that will help you enter a new ID if the one you typed has not yet been recorded.

So to sum up.

The main Form holds the ID and some standard information about the ID.

The Sub Form will hold many records of repeating data. Like Dates worked or Various qualifications etc.

The ID will be recorded automatically when you create a new record in the Sub Form.

If you want to discuss AutoNumber as your Primary Key then please say so and I will be glad to help. AutoNumber is the prefered choice of all good programers. It is also my only choice of ID.

Hope this helps.
 

RainLover

VIP From a land downunder
Local time
Today, 11:27
Joined
Jan 5, 2009
Messages
5,041
Bob

I got the feeling that you suggested placing a Combo Box in the Sub Form and Selecting the ID from there.

Is that what you meant or did I misread.
 

djossh

Registered User.
Local time
Today, 04:27
Joined
Oct 19, 2011
Messages
89
We can come back to the ID later if you wish. For now I will simply say that using Autonumber is a better method.

I would think that as I suggested before that you have a problem with your Relationships.

Your Sub Form is Joined to the Main form and should be linked via the Employee ID. If you have done this correctly then the sub form will only show records with the same ID as in the Main Form. Make sure you have also set Referential Intregity in the Database window as well.

Once you start entering information into a new Record in the Sub Form the ID will auto populate.

As I said "No need for code"

The use of a Combo box would be good in the Main Form for searching. You can set this to limit to list. There is also code about that will help you enter a new ID if the one you typed has not yet been recorded.

So to sum up.

The main Form holds the ID and some standard information about the ID.

The Sub Form will hold many records of repeating data. Like Dates worked or Various qualifications etc.

The ID will be recorded automatically when you create a new record in the Sub Form.

If you want to discuss AutoNumber as your Primary Key then please say so and I will be glad to help. AutoNumber is the prefered choice of all good programers. It is also my only choice of ID.

Hope this helps.


Well explained...... I appreciate all the help... Thank a lot.
 

RainLover

VIP From a land downunder
Local time
Today, 11:27
Joined
Jan 5, 2009
Messages
5,041
Pleased that you found it helpfull.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 02:27
Joined
Sep 12, 2006
Messages
15,653
if course, if you really want to enter the code directly - have two combo boxes

make one show names, and the other the recordid, both bound to the same data
then users can use either the recordid combo box or the name box

I can see on something like an employee system, using the employee code directly would be useful

you probably need some code to reposition the form to the selected record, but I expect you already have that.
 

Users who are viewing this thread

Top Bottom