( INSTR( 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", LEFT( XYZ, 1 ), vbTextCompare ) > 0 )
When you add that statement of purpose to your prior discussion, then... "Is this the best way of achieving this?" Almost certainly not.
The reason I say that is that the implication of doing this via some kind of field validation rule is that your users see a raw table. If that is so, you are hopelessly exposed to all sorts of ills. You have little to no control over what happens when users see tables.
The best way to do this is, when you add a new customer and give them a code, do so though a form where you can do extensive (or simple) VBA operations to do your screening, and you use the form's _BeforeUpdate event to do final validity tests. The _BeforeUpdate event can be canceled (i.e. blocked from completion) which means you can stop entry of a bad code before it happens.
There are various schools of thought here, but most of the experts would agree that an extensive Form_BeforeUpdate routine would be the best way to assure proper formatting for the fields you want to enter. Not just your code, but anything else that you really wanted to be entered at that point. Doing it through a form is going to be the best solution to get maximum flexibility and maximum effect.
There is another school of thought that says when you use a form, put validation code in each control's _LostFocus routine and thus put individual field validation associated with each specific field - whereas doing validation in the _BeforeUpdate routine tests each field in turn and so can get a bit complex. Which way is right? Damned if I know. Opinions differ. But I'm pretty sure that using a field validation code is asking a bit much for what sounds like a potentially complex selection process.
Think about your goals and maybe tell us IN WORDS what you are trying to do. Don't dwell on mechanisms, but tell us desired results.
The safest and most comprehensive approach is to create the validity check in the table definition.I want a validation rule making the first character a letter
The safest and most comprehensive approach is to create the validity check in the table definition.
Design view of the table
ValidationRule for IDCode: LIKE "[A-Z]*"
ValidationText: "Give me a letter at first"
what if there is no number entered?Thanks for that. Seems to be just what I want
Me, as a person who has never worked with Access in depth, have always hated table side validation rules.The safest and most comprehensive approach is to create the validity check in the table definition.
Design view of the table
ValidationRule for IDCode: LIKE "[A-Z]*"
ValidationText: "Give me a letter at first"
What works at table level and directly in connection with the database engine does not have to be delegated to a front end. Entries in a table can be made in different ways: via bound forms, via action queries, via writing recordsets, via standard imports, via manual entries directly into the table.Who remembers the validations that are in place, and who will go to the trouble to change them to vba?
Not trying to urge you, but indexes can be moved to tables in sql server in upsizing process. I didn't say anything about indexes, but validation rules.Would you want to remove a unique index from the table definition to avoid unwanted duplicates and implement it using VBA, comprehensively for all later extensions and without errors?
Thanks. I was only waiting for him to admit it.Validation rules on tables become constraints when moved to SQL Server using SSMA.
Whist this sort of works, in reality, they are generally a right royal PITA, as they simply generate a OBDC error if the constraint isn't adhered to.
So you have to go into every form and code in the validation in the before update events to handle then so the ODBC error is kept at bay, or remove the constraints and then still program them on the form as there isn't another way of ensuring data integrity.
Thanks. I'll take a look.Every database should be able to implement such simple standards if MS Access can.![]()
W3Schools.com
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.www.w3schools.com