How to Convert Field Text Case in MS Access: Upper, Lower, Proper, and Sentence CaseConverting text case in Microsoft Access is a common task when you need data consistency, create professional-looking reports, or prepare information for exports and mailings. Access provides built-in functions for uppercase, lowercase, and proper case; sentence case requires a bit more work. This article explains several methods — using queries, VBA, expressions in forms and reports, and update queries — so you can choose the approach that best fits your database, skill level, and safety requirements.
Overview of common Access text-case functions
- UCase(string) — converts all letters in string to uppercase (e.g., “hello” → “HELLO”).
- LCase(string) — converts all letters in string to lowercase (e.g., “Hello” → “hello”).
- StrConv(string, vbProperCase) — converts to Proper Case (title case, e.g., “john doe” → “John Doe”). StrConv can also be used for other locale-aware conversions.
- Sentence case (only the first letter of each sentence capitalized) is not provided as a single built-in function in Access; it requires a custom expression or VBA routine.
Methods
1) Using a Select query (non-destructive preview)
Use this when you want to preview changes without altering stored data.
Example SQL:
SELECT [ID], [MyTextField], UCase([MyTextField]) AS UpperText, LCase([MyTextField]) AS LowerText, StrConv([MyTextField], 3) AS ProperText FROM MyTable;
- Replace MyTable and MyTextField with your table and field names.
- StrConv with argument 3 corresponds to vbProperCase.
- To preview sentence case in a select query, use a calculated field calling a VBA function (see section 4).
2) Using an Update query (permanent changes)
Use an Update query to overwrite the field in your table. Always back up your data before running update queries.
Uppercase:
UPDATE MyTable SET MyTextField = UCase([MyTextField]);
Lowercase:
UPDATE MyTable SET MyTextField = LCase([MyTextField]);
Proper case:
UPDATE MyTable SET MyTextField = StrConv([MyTextField], 3);
Sentence case (example using VBA function — see section 4):
UPDATE MyTable SET MyTextField = dbo_SentenceCase([MyTextField]);
Note: Access calls the VBA function by name (no module prefix required if in a standard module); the example uses dbo_SentenceCase only as an illustrative name.
3) Use expressions in forms and reports (display-only)
If you want to change case only where data is shown (without modifying stored data), set a control’s ControlSource or an expression to use the functions.
- In a text box ControlSource:
- For uppercase: =UCase([MyTextField])
- For lowercase: =LCase([MyTextField])
- For proper: =StrConv([MyTextField],3)
- For sentence case: =dbo_SentenceCase([MyTextField]) — requires VBA function.
This approach is safe and ideal for reports, forms used for display, or when you must preserve original data.
4) VBA functions for sentence case and advanced rules
Access lacks a native SentenceCase function. Below are two VBA options: a simple sentence-case function and a more advanced routine that handles punctuation and multiple sentences.
To add either function, open the Visual Basic Editor (Alt+F11), insert a new Module, and paste one of the following functions.
Simple sentence-case function (first character uppercase, rest lowercase):
Public Function SimpleSentenceCase(ByVal txt As Variant) As Variant If IsNull(txt) Then SimpleSentenceCase = Null Exit Function End If Dim s As String s = Trim(CStr(txt)) If Len(s) = 0 Then SimpleSentenceCase = s Exit Function End If SimpleSentenceCase = UCase(Left(s, 1)) & LCase(Mid(s, 2)) End Function
- Good for single short phrases or fields where you want only the first letter capitalized.
Advanced sentence-case function (handles multiple sentences and common punctuation):
Public Function SentenceCase(ByVal txt As Variant) As Variant If IsNull(txt) Then SentenceCase = Null Exit Function End If Dim s As String, outS As String Dim i As Long, ch As String, prev As String s = CStr(txt) outS = "" prev = " " ' treat start as whitespace so first letter will be capitalized For i = 1 To Len(s) ch = Mid$(s, i, 1) If prev = "." Or prev = "?" Or prev = "!" Then ' Capitalize first alphabetic character after sentence-ending punctuation and possible spaces If ch Like "[A-Za-z]" Then outS = outS & UCase(ch) Else outS = outS & ch End If ElseIf i = 1 Then outS = outS & UCase(ch) Else outS = outS & LCase(ch) End If prev = ch Next i SentenceCase = outS End Function
Notes and caveats:
- This advanced function lowercases characters except those determined to start sentences. It doesn’t handle abbreviations (e.g., “e.g.”, “Mr.”) or names like “McDonald” correctly in all cases. You can extend it with exceptions or regex-style logic if needed.
- After adding the function, you can call it from queries, forms, reports, or update queries just like a built-in function: e.g., SELECT SentenceCase([MyTextField]) AS SentCase FROM MyTable;
5) Handling international characters and locale
- StrConv and the VBA UCase/LCase are culture-aware for many locales, but behavior may vary with accented characters and non-Latin scripts. Test with representative data.
- For advanced locale-specific casing (Turkish dotted/dotless i), you may need additional logic or Windows locale-aware APIs; Access/VBA default behavior might not match your target language rules.
6) Best practices and safety
- Always back up your table before running Update queries. Consider working on a copy of the table when testing transformations.
- Prefer display-only expressions in forms/reports if underlying data must remain unchanged.
- Use transactions (if supported by your backend, e.g., SQL Server linked table) or run the update in batches for very large tables.
- Keep a log of transformations (a backup column or audit table) if you need to revert changes or track what was modified.
7) Examples of real-world use cases
- Standardizing customer names before mailing to reduce returned mail and improve personalization. Use Proper Case for names and Sentence Case for address lines if you prefer sentence-style formatting.
- Preparing product descriptions for an export feed where uppercase/lowercase matters for matching with external systems.
- Formatting report headers or labels on-the-fly with control expressions so underlying data remains unmodified.
8) Troubleshooting common issues
- Function not available in query: Ensure the VBA function is in a standard module (not a class or form module) and the database is trusted (set in Access security options).
- Strange capitalization for accented characters: Test with sample data and consider custom routines for specific languages.
- Update query error on linked tables: If table is linked to SQL Server or another backend, perform transformations on the server side where possible (T-SQL has UPPER()/LOWER() functions) or pull data into Access, transform, then push back.
Quick references (cheat sheet)
- Uppercase (display): =UCase([FieldName])
- Lowercase (display): =LCase([FieldName])
- Proper case (display): =StrConv([FieldName], 3)
- Sentence case (display): =SentenceCase([FieldName]) — requires VBA function
If you want, I can:
- Provide a ready-to-run module with enhanced sentence-case handling (with exceptions for common abbreviations), or
- Convert a specific table/field using an Update query — tell me your field and table names and whether you want a backup column created first.
Leave a Reply