Hi,
I'm wondering if its possible to use a variable when setting the focus to a particular form and field. I have a table with the name of the forms and fields. Based on the current form that's open and what other forms are open, I want the code to lookup in the table which form and field it should go to next when a tab or return is pressed. Setting the form and field that get the focus using a variable seems to be a problem. My code looks like this:
Private Sub LBTST4_MON_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case Shift
Case 1 ' Go backwards
Case Else 'Go forwards
If KeyCode = 9 Or KeyCode = 13 Then
Dim dform, dfield, formname As String
'look up the form and field to go to next
dform = FormNav1(Forms!frmmaster1!frameGroup, "frmTest4Rm", 1)
dfield = FormNav2(Forms!frmmaster1!frameGroup, "frmTest4Rm", 1)
Debug.Print dform, dfield
Me.Parent.[" & dform & "].SetFocus
Me.Parent.[" dform & "]![" & dfield &"].SetFocus
KeyCode = 0
End If
End Select
End Sub
I get an error message when it gets to the setfocus lines. Anyone know how to do this better?
Thanks,
Jimmy211
I'm wondering if its possible to use a variable when setting the focus to a particular form and field. I have a table with the name of the forms and fields. Based on the current form that's open and what other forms are open, I want the code to lookup in the table which form and field it should go to next when a tab or return is pressed. Setting the form and field that get the focus using a variable seems to be a problem. My code looks like this:
Private Sub LBTST4_MON_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case Shift
Case 1 ' Go backwards
Case Else 'Go forwards
If KeyCode = 9 Or KeyCode = 13 Then
Dim dform, dfield, formname As String
'look up the form and field to go to next
dform = FormNav1(Forms!frmmaster1!frameGroup, "frmTest4Rm", 1)
dfield = FormNav2(Forms!frmmaster1!frameGroup, "frmTest4Rm", 1)
Debug.Print dform, dfield
Me.Parent.[" & dform & "].SetFocus
Me.Parent.[" dform & "]![" & dfield &"].SetFocus
KeyCode = 0
End If
End Select
End Sub
I get an error message when it gets to the setfocus lines. Anyone know how to do this better?
Thanks,
Jimmy211