Hi Kitcat,
Piggybacking on Douglas Steele’s solution, another approach is in form
design instead of query design. If you have a data entry/edit form, you can
achieve your task in a couple of different ways using an AfterUpdate event
procedure.
If you have a text control named “Title†on your form for the table field
with the same name (control source in property sheet for the text control),
here is an event procedure that works for me:
Private Sub Title_AfterUpdate()
If IsNull(Title) Or Not IsNull(Title) And _
Left([Title], 4) = "The " Then
Title = Mid$([Title], 5) & ", The"
ElseIf IsNull(Title) Or Not IsNull(Title) And _
Left([Title], 2) = "A " Then
Title = Mid$([Title], 3) & ", A"
ElseIf IsNull(Title) Or Not IsNull(Title) And _
Left([Title], 3) = "An " Then
Title = Mid$([Title], 4) & ", An"
ElseIf IsNull(Title) Or Not IsNull(Title) And _
IsNull([Title]) Then
Title = Null
End If
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
End Sub
Note the one extra space after the last letter in quotes when writing “A “,
“An “, “The “. This extra space eliminates unwanted chopping off of such
words as “Another†or Theaterâ€, etc.
I personally add a field in my book table called NameKey which stores the
book titles in capital letters and identifies the Book ID in parentheses a
few spaces to the right of the book title. I use the NameKey field to sort
all records alphabetically. Example:
STREETCAR NAMED DESIRE, A (101)
INCONVENIENT TRUTH, AN (102)
STRANGER, THE (103)
I also use the NameKey field in an unbound combo box control on my form to
provide me a drop down list of all book titles allowing me to select a title
and display that record’s information on the current form view.
The actual book title can appear on the form in the Title text control (and
in the table’s Title field) in its normal order:
A Streetcare named Desire
An Inconvenient Truth
The Stranger
The AfterUpdate event procedure for the Title text control stores the
desired formatted information in the NameKey field. Here is the event
procedure that works for me:
Private Sub Title_AfterUpdate()
If IsNull(NameKey) Or Not IsNull(NameKey) Then
NameKey = UCase([Title] & " (" & [BookID] & ")")
End If
If IsNull(NameKey) Or Not IsNull(NameKey) And _
Left([Title], 4) = "The " Then
NameKey = UCase(Mid$([Title], 5) & ", THE (" & [BookID]
& ")")
ElseIf IsNull(NameKey) Or Not IsNull(NameKey) And _
Left([Title], 2) = "A " Then
NameKey = UCase(Mid$([Title], 3) & ", A (" & [BookID] &
")")
ElseIf IsNull(NameKey) Or Not IsNull(NameKey) And _
Left([Title], 3) = "AN " Then
NameKey = UCase(Mid$([Title], 4) & ", AN (" & [BookID] &
")")
ElseIf IsNull(NameKey) Or Not IsNull(NameKey) And _
IsNull([Title]) Then
NameKey = Null
End If
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
End Sub
The NameKey field with Event Procedure is valuable in alphabetically listing
such organizations as AMERICAN RED CROSS, THE , SALVATION ARMY, THE, and
KAISER FOUNDATION, THE, etc.
Hope this helps.
- - - -
Tank