Hello Friends!
Happy Friday and V-Day!
The code below is used to change the value of a field to the next one. (Found on Google or possibly this forum, works pretty well)
I am trying to write a sub so instead of creating a sub for every control, I would like to create a sub as below so I can call on different controls easily.
Public Sub ScrollNext (FieldName as String)
(To call, I cando ScrollNext("CustomerName")
How do we reference the control using the string provided when calling the sub? Code below is firing a syntax error.
Thank you for your time!
Cheers!
Happy Friday and V-Day!
The code below is used to change the value of a field to the next one. (Found on Google or possibly this forum, works pretty well)
Code:
Private Sub Combo385Scroll()
[Combo385].SetFocus
If [Combo385].ListIndex <> [Combo385].ListCount - 1 Then
[Combo385].ListIndex = [Combo385].ListIndex + 1
Else
[Combo385].ListIndex = 0
End If
End Sub
I am trying to write a sub so instead of creating a sub for every control, I would like to create a sub as below so I can call on different controls easily.
Public Sub ScrollNext (FieldName as String)
(To call, I cando ScrollNext("CustomerName")
How do we reference the control using the string provided when calling the sub? Code below is firing a syntax error.
Code:
Public Sub ScrollNext(FieldName As String)
(FieldName).SetFocus 'I want this like to execute CustomerName.SetFocus. Given that CustomerName as String was used to call this sub.
If Me(FieldName).ListIndex <> Me(FieldName).ListCount - 1 Then
Me(FieldName).ListIndex = Me(FieldName).ListIndex + 1
Else
Me(FieldName).ListIndex = 0
End If
End Sub
Thank you for your time!
Cheers!
Last edited: