2ndHand
asked on
Using the keyboard arrow key to move around...
The following is my example code:
Private Sub Form_Load()
Dim myConnection As String
myConnection = "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=" _
& "C:\MyDatabase.mdb;Persist Security Info=False"
With adodc1
.ConnectionString = myConnection
.CommandType = adCmdUnknown
.RecordSource = "SELECT * FROM MyTable"
.Refresh
.Recordset.MoveFirst
End With
Set DataGrid1.DataSource = adodc1
DataGrid.AllowUpdate = True
End Sub
I can move the cursor go to any cell by using the up & down, and the left & right arrow keys.
However, if I change the cell value, then I can't move the cursor anymore until I push enter.
In Access database, I can move around the cursor by using arrow keys right after I change the cell value. Does anyone know how to modify the above code so that I can move around the cursor by using arrow keys without hitting the enter button?
Thanks
Private Sub Form_Load()
Dim myConnection As String
myConnection = "Provider=Microsoft.Jet.OL
& "C:\MyDatabase.mdb;Persist
With adodc1
.ConnectionString = myConnection
.CommandType = adCmdUnknown
.RecordSource = "SELECT * FROM MyTable"
.Refresh
.Recordset.MoveFirst
End With
Set DataGrid1.DataSource = adodc1
DataGrid.AllowUpdate = True
End Sub
I can move the cursor go to any cell by using the up & down, and the left & right arrow keys.
However, if I change the cell value, then I can't move the cursor anymore until I push enter.
In Access database, I can move around the cursor by using arrow keys right after I change the cell value. Does anyone know how to modify the above code so that I can move around the cursor by using arrow keys without hitting the enter button?
Thanks
ASKER
Thanks for your help.
The above sendkeys code works perfectly. However, I also need the cursor can move up or down as well. I tried to do something like below but it was not working. After I hitted either the up or down arrow key, the cursor disapppeared. Can you tell me what is wrong. How can I fix the problem?
Private Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyRight Or KeyCode = vbKeyLeft Or _
KeyCode = vbKeyUp Or KeyCode = vbKeyDown Then
If DataGrid1.CurrentCellModif ied Then
DataGrid1.EditActive = False
Select Case KeyCode
Case vbKeyLeft
SendKeys "{LEFT}"
Case vbKeyRight
SendKeys "{RIGHT}"
Case vbKeyUp
SendKeys "{UP}"
Case vbKeyDown
SendKeys "{DOWN}"
End Select
End If
End If
End Sub
The above sendkeys code works perfectly. However, I also need the cursor can move up or down as well. I tried to do something like below but it was not working. After I hitted either the up or down arrow key, the cursor disapppeared. Can you tell me what is wrong. How can I fix the problem?
Private Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyRight Or KeyCode = vbKeyLeft Or _
KeyCode = vbKeyUp Or KeyCode = vbKeyDown Then
If DataGrid1.CurrentCellModif
DataGrid1.EditActive = False
Select Case KeyCode
Case vbKeyLeft
SendKeys "{LEFT}"
Case vbKeyRight
SendKeys "{RIGHT}"
Case vbKeyUp
SendKeys "{UP}"
Case vbKeyDown
SendKeys "{DOWN}"
End Select
End If
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect solution!
Thanks
Thanks
try something like this, this code changes edit mode to false and focus is in the same cell. if you want to move to next or previous cells use sendkeys and either send left or right arrow keys depending on the key pressed.
Private Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyRight Or KeyCode = vbKeyLeft Then
If DataGrid1.EditActive Then
DataGrid1.EditActive = False
End If
End If
End Sub
code with sendkeys
Private Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyRight Or KeyCode = vbKeyLeft Then
If DataGrid1.CurrentCellModif
DataGrid1.EditActive = False
If KeyCode = vbKeyLeft Then
SendKeys "{LEFT}"
Else
SendKeys "{RIGHT}"
End If
End If
End If
End Sub