Microsoft Office Tutorials and References
In Depth Information
Access Procedures
'Test if something has been selected¶
If Me.FullName.SelLength > 0 Then¶
' Move the initials¶
Me.Initials = Trim(Mid(FullName, Me.FullName.SelStart + 1,
Me.FullName.SelLength + 1))¶
' Move the last name¶
Me.LastName = Trim(Mid(FullName, Me.FullName.SelStart +
Me.FullName.SelLength + 1))¶
' Test for name without title¶
If Me.FullName.SelStart > 0 Then¶
' Skip filling title field¶
Me.Title = Left(FullName, Me.FullName.SelStart - 1)¶
End If¶
' Refresh the form to reflect changes¶
Me.Refresh¶
End If¶
End Sub¶
The MID function hse three parameters representing string, start position, and
length. Leaving out the length will capture all the characters until the end. For
the Initials, just the selected part is needed.
The TRIM function removes leading and trailing spaces. Here, that makes the
correction of the length and/or start position obsolete. One or more spaces
between the different sections of the FullName are also not relevant because all
strings are now separated by one space.
The real work is done based on the field properties SelLength and SelStart,
which will hold the dynamically selected part of the field. A problem arises
when FullName is without a title. This causes the Me.Title = Left(FullName,
Me.FullName.SelStart – 1) to fail because a Left(string,–1) is impossible. Thus,
an additional IF is placed in the code to skip the filling in case the selection
starts at the beginning of the field.
Acs
6. Finally, you need to add the code shown below to the LastName text
box.
Double-click the field after the MouseUp event in the Properties window
for the LastName text box to get the text Event Procedure. Press the
button […] to go to the code section.
7. Select the LastName option in the left drop-down of the VBE and then
the MouseUp in the right drop-down to open the proper code window.
Private Sub LastName_MouseUp(Button As Integer, Shift As Integer, X As
Single, Y As Single)¶
'Initialize field¶
Me.MiddlePart = ¶
Search JabSto ::




Custom Search