Best way to Add new record using a form

S

Silvio

What's the best way to enter a new record in a table (I know there are so
many ways)?

Before the record is saved:
1. All the field need to be validated before the the record is actually
entered/saved
2. If the projet number already exting in the table then the record should
not be entered.

What I have done is:
Create a new form based on the table
Create unbound control where the user will enter data, then a command button
will validate each filed and if the data is correct then the record is saved
by:

me.Proj = TxProj
me.Desc = TxDesc and so on

Is this a good way, or there is better more reliable and fater method?
 
M

Marshall Barton

Silvio said:
What's the best way to enter a new record in a table (I know there are so
many ways)?

Before the record is saved:
1. All the field need to be validated before the the record is actually
entered/saved
2. If the projet number already exting in the table then the record should
not be entered.

What I have done is:
Create a new form based on the table
Create unbound control where the user will enter data, then a command button
will validate each filed and if the data is correct then the record is saved
by:

me.Proj = TxProj
me.Desc = TxDesc and so on

Is this a good way, or there is better more reliable and fater method?


The usual way is to just use bound controls on the form.
Then use the form's BeforeUpdate event procedure to validate
the values. If a value is unacceptable, use a message box
to tell the user and set the procedure's Cancel argument to
True to prevent the save.

It would probably be a good idea to also check the project
number in the text box's BeforeUpdate event procedure and
give an immediate error message if it's a duplicate:

If DCount("*", "thetable", "projnum=" & Me.Proj) > 0 Then
MsgBox "Duplicate project number"
Cancel = True
End If

If you have a unique index for the projnum field in the
table, there is no real need for that code. The duplicate
index will automatically be rejected, probably with an
obscure error message about a key violation.
 
J

John W. Vinson

Maybe that depends on your application. I use the forms for production data
entry so when my user hits ENTER they save the current record and are on a
new. This is more efficient for us than using the mouse.

ummm...

no code whatsoever is needed to accomplish this. You have to go a fair bit out
of your way to create a form which requires any use of the mouse at all.
 
J

John W. Vinson

Yes but lots of folks put SAVE, NEXT RECORD, NEW RECORD, etc., buttons on
their forms that require a mouse click. And there are times when explicitely
saving the record is prudent but not in my apps.

One keyboard-friendly hint is to use hotkeys: if you set the Caption of the
buttons to &SAVE, &NEXT RECORD, NEW &RECORD then typing alt-S, alt-N and alt-R
respectively will have the same effect as clicking the button.
 

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