What I'd like the code to do is to advance the userform frontwards (right arrow key) or backwards (left arrow key) like the userform does right now when the specific command buttons are currently clicked:
I'm just showing the code to advance to the next record on the spreadsheet ("cmdNext")... the other one (go to the previous record; "cmdPrevious") is the same except this code has '-1' instead)
The red arrows in the pic below shows how it works right now... the above code is ran when the right green command button (smdNext) is clicked (the left one does the same except it goes backwards using -1 instead of 1). This will make the userform to clear its contents and then reload everything with the next record BELOW the current record (row) that is being viewed... So in this example, the userform is displaying the data from the row with "22-1245" in column A... clicking on the right green command button will advance it to the next record, "22-1246"
I want to modify the code so when the right arrow key is pressed it will run the cmdNext code, and when the left arrow is pressed, it will run the cmdPrevious code. How would I do that? Thanks!
I'm just showing the code to advance to the next record on the spreadsheet ("cmdNext")... the other one (go to the previous record; "cmdPrevious") is the same except this code has '-1' instead)
VBA Code:
Private Sub cmdNext_Click()
Dim ctl
' FIRST CLEAR ALL CHECKBOXES & TEXTBOXES THAT CONTAINED DATA FROM PREVIOUS INCIDENT ID RECORD.
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.TextBox Then
ctl.Text = ""
ElseIf TypeOf ctl Is MSForms.ComboBox Then
ctl.Object.value = ""
ElseIf TypeOf ctl Is MSForms.CheckBox Then
ctl.Object.value = False
End If
Next ctl
' NOW FIND THE NEXT VISIBLE ROW **BELOW** THE CURRENT INCIDENT ID RECORD & POPULATE THE USERFORM WITH THAT DATA
If Not FoundCell Is Nothing Then
Do
Set FoundCell = FoundCell.Offset(1)
Loop While FoundCell.EntireRow.Hidden = True
Debug.Print FoundCell.Row
GetRecord FoundCell.Row
End If
End Sub
The red arrows in the pic below shows how it works right now... the above code is ran when the right green command button (smdNext) is clicked (the left one does the same except it goes backwards using -1 instead of 1). This will make the userform to clear its contents and then reload everything with the next record BELOW the current record (row) that is being viewed... So in this example, the userform is displaying the data from the row with "22-1245" in column A... clicking on the right green command button will advance it to the next record, "22-1246"
I want to modify the code so when the right arrow key is pressed it will run the cmdNext code, and when the left arrow is pressed, it will run the cmdPrevious code. How would I do that? Thanks!