This is probably really simple!

AuroX7

Registered User.
Local time
Today, 10:08
Joined
Feb 22, 2006
Messages
44
Hey guys, I'm just wondering how I could limit a field to using from 2 - 20 letters. If I placed the letter "a", I'd get an error saying how at least 2 letters must be there, and a maximum of 20. How would I do this?

Lastly, how can I make it so when I enter data into a form, I can click a button which adds it all into the table?
When I do it normally, it's automatically transferred into the table as I type it into the form.

This is incredibly simple I know, but I am a n00b at Access. ^_^

Thanks guys.
 
Last edited:
Use after update event and use Len() to check the no. of character entered.

and regarding your second question, there are so many way to do that.

you can use SQL command, openrecordset addnew....etc

but the easiest way for u is to insert the table and create an after update event to update all fields at once
 
1. Set the field size to 20 and in the Form's BeforeUpdate event, check the length by using the Len() function.

Code:
If Len(Me.YourField) < 2 Then
    Cancel = True
    Msgbox "field must be between 2 and 20 characters in length", vbOKOnly
    Me.YourField.SetFocus
End If
When I do it normally, it's automatically transferred into the table as I type it into the form.
2. Access does not save each character as it is typed. Access saves the entire record when
a. the form is closed.
b. the record pointer is moved forward or back
c. focus moves from a main form to a subform or vice versa
In order to control record saving, you need to understand the form's BeforeUpdate event and how to cancel it. When ever Access attempts to save a record because it is dirty, the last event it fires is the Form's BeforeUpdate event. That is where you need to put much of your error handling.

If you choose to use a save button, the only code that belongs in the button is:

DoCmd.RunCommand acCmdSaveRecord

This command will tell access to save the current record. Access will then run the BeforeUpdate event and execute any code you have there that edits the data.
 

Users who are viewing this thread

Back
Top Bottom