Posts Tagged ‘Microsoft Access bullets’

Adding Bullets in Microsoft Access

Monday, May 17th, 2010

Ever wanted to add bullets in Microsoft Access 2003?  I have usually inserted a dash, but playing around recently found I could create a button to insert a bullet.  Here is the solution.

Assume you have a textbox called txtInfo. You need to track where the cursor is in the textbox.  To do this create a place to record the position.

Dim intCursorPosition As Integer

In the On Click and On Keydown events for the textbox do the following.

Private Sub txtInfo_Click()
intCursorPosition = Me.txtInfo.SelStart
End Sub

Private Sub txtInfo_KeyDown(KeyCode As Integer, Shift As Integer)
intCursorPosition = Me.txtInfo.SelStart
End Sub

Put a button on the form beside the textbox.  Call it btnBullet  Post the following code into the On Click event

Private Sub btnBullet_Click()

Me.txtInfo.SetFocus
Me.txtInfo = Left(Me.txtInfo, intCursorPosition) & vbCrLf & Chr(149) & ”  ” & Mid(Me.txtInfo, intCursorPosition + 1, Me.txtInfo.SelLength – intCursorPosition)
Me.txtInfo.SetFocus
Me.txtInfo.SelStart = intCursorPosition + 5

End Sub

How it works

The On Click and Keydown events will have told you where the cursor was located prior to the button being selected.  That information is stored in intCursorPosition.  The first thing that needs to happen is to return the focus to the textbox.

You now construct the contents of the textbox by taking the text to the left of the cursor position, adding a return, adding Chr(149) which is a bullet, adding two spaces, and finally adding the text to the right of the cursor position.  The rest of the code is to put the cursor after the bullet and two blank spaces.