Navigation:  Articles > Apr-1999 >

Tip: Shortcuts for Symbols

Previous pageReturn to chapter overviewNext page

Militaru Sorin            
I like the way Microsoft Word inserts symbols using shortcut keys defined by the user. Unfortunately, Microsoft Access doesn't have an equivalent feature. Here's the method that I use to insert symbols or special characters. The symbols and the shortcut keys defined are stored in a table called "tShortCutKey" with the structure shown in Table 1. The ShortCutKey field is in the format Format$(Shift) & "+" & Format$(KeyCode), where Shift and KeyCode are the values returned by KeyDown event procedure.
Table 1. The tShortCutKey table.

Field Name









The pgInsertSymbol subroutine uses the table to load symbols:

Sub pgInsertSymbol (pintKeyCode As Integer, _

  pintShift As Integer) 

Dim strShortCutKey As String 

Dim intSelStart As Integer 

Static fLoaded As Integer 

If Not fLoaded Then 


  fLoaded = True 

End If 

strShortCutKey = _

  Format$(pintShift) & "+" & _


If InStr(strKeyList, strShortCutKey) <> 0 Then 

  intSelStart = Screen.ActiveControl.SelStart 

  Screen.ActiveControl.text = _

    Left(Screen.ActiveControl.text, intSelStart) _

    & DLookup("Symbol", "tShortCutKey", _

    "ShortCutKey='" & strShortCutKey & "'") & _

    Mid(Screen.ActiveControl.text, intSelStart + _

    Screen.ActiveControl.SelLength + 1) 

   Screen.ActiveControl.SelStart = intSelStart + 1 

End If 

End Sub

To call the routine, you add this line to the KeyDown event of any text box where you want to display sales:

pgInsertSymbol KeyCode, Shift

The routine uses a global variable loaded with the list of shortcut keys defined in the table. The pgLoadList routine loads that variable:

Dim strKeyList As String


Sub pgLoadList () 

Dim db As Database 

Dim rec As Recordset 

Set db = DBEngine.Workspaces(0).Databases(0) 

Set rec = db.OpenRecordset("tShortCutKey", _ 


strKeyList = "" 

Do While Not rec.EOF 

  strKeyList = strKeyList & Chr(13) & Chr(10) & _ 




End Sub