Public Sub NavigateThruCells(KeyAscii As Integer, mfgDeps As MSFlexGrid)
Dim strContents As String
With mfgDeps
'Get the text contents of the cell with focus
strContents = .TextMatrix(.RowSel, .ColSel)
'Check if the backspace key was pressed
If KeyAscii = 8 Then
'Don't do anything if the backspace key was pressed
'and the cell with focus is empty
If Trim(strContents) = "" Then Exit Sub
'Delete the last character
strContents = Mid(strContents, 1, Len(strContents) - 1)
.TextMatrix(.RowSel, .ColSel) = strContents
'Check if the enter key was pressed
ElseIf KeyAscii = 13 Then
'Check if the cell with focus is on the last collumn
'If not then focus on the next collumn
If .Col < .Cols - 1 Then
.Col = .ColSel + 1
'If it is the last collumn then go back to the
'first collumn but adjust to the next row
Else
.Col = 1
'Check if the cell with focus belongs to the
'last row. If not then go to the next row
If .Row < .Rows - 1 Then
.Row = .RowSel + 1
'If it is the last row then check for an empty cell
Else
If CheckIfFull(mfgDeps) = False Then
.Row = 1
.Col = 1
'If all cells are not empty then add a
'new row and focus on that row
Else
.Rows = .Rows + 1
.Col = 1
.Row = .RowSel + 1
End If
End If
End If
'If the neither the backspace nor the enter
'key was pressed, then concatenate the pressed key
'with the string in the cell
Else
'Do nothing if the escape key was pressed
If KeyAscii = 27 Then Exit Sub
.TextMatrix(.RowSel, .ColSel) = _
.TextMatrix(.RowSel, .ColSel) & Chr(KeyAscii)
End If
End With
End Sub