Loop through access form control using Tab Index (1 Viewer)

morsy_soliman

New member
Local time
Today, 09:10
Joined
Apr 26, 2017
Messages
5
Hello All,

I am using the VBA code below in a Public Function(ByRef frm As Form) to loop through the control of any form to look for any control tagged by "R" is empty.

The code is working well but it goes alphabetically based on the name of the control.

I am looking if somebody kindly help me to loop through the control using their tab index?

"I am using the VBA code" Please use code tags
Code:
Dim ctl As Control
Dim CurrentForm As Form
Set CurrentForm = Screen.ActiveForm
Set ctl = CurrentForm.ActiveControl


For Each ctl In frm.Controls
If Left(Right(ctl.Tag, 4), 1) = "R" Then
If IsNull(ctl.value) = True Then
ctl.SetFocus

Select Case TypeName(ctl)
Case "TextBox"


Case "ComboBox"



End Select
End If
End If
Next ctl
 
Last edited by a moderator:

Gasman

Enthusiastic Amateur
Local time
Today, 14:10
Joined
Sep 21, 2011
Messages
14,053
Are you sure, as this is mine from a form? Try debug.print to see

Text1
Label2
Text3
Label4
List5
lstMonthNum_Label
Lstavailable
lstDates_Label
Command11
lstSelected
Cmdadd
CmdRemove
Combo16
Label17
Cmdprevious
cmdNext
Field2
Label20
Command21
txtTime
Label23
Command24
Text25
Label26
Cbosheets
cboSortBy_Label
Cmdsave
btnNew
Check29
Label30
Check31
Label32
cmdZoom
Text34
Label35
 

Minty

AWF VIP
Local time
Today, 14:10
Joined
Jul 26, 2013
Messages
10,355
Just as a suggestion;

I would return a string of all the missing data control names or possibly their datasheet caption if you need something more meaningful, then present that in a message box, rather than bothering the end user each and every time something is missing?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 09:10
Joined
Feb 28, 2001
Messages
27,003
Two comments:

1. While it is not a cardinal sin for new members to do this, we dislike cross-posted requests. I.e. posted in more than one forum. We might waste our time on a matter you have already resolved and as it is, we are often stretched thin trying to help. If you advise us ahead of time that you have cross-posted AND you provide us with a link then we can decide whether you still need our help before we put in too much effort.

2. It is not going to be possible in ONE step to do what you ask. You could, however, keep a table with the control names and as a 2nd column, the tab order numbers. Gather the names and numbers in whatever order you get, but before presenting the results, open that table using a query with an ORDER BY of the field containing the tab order and a WHERE clause that removes things with a tab order less than 1. Divide and conquer!
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:10
Joined
May 21, 2018
Messages
8,463
You can only loop by the Z index. Which you cannot control. It is determined by when and where you add the control.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:10
Joined
May 21, 2018
Messages
8,463
So you can hard code your control names. Example ctrl1, ctrl2,...ctrln. Then loop from 1 to N.
For i = 1 to N
If me.controls("ctrl"&i).tag
 

Cronk

Registered User.
Local time
Tomorrow, 01:10
Joined
Jul 4, 2013
Messages
2,770
Or better still, if the tag name required is 'R' then
For i = 1 to N
If me.controls("ctrlR" & i).tag
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:10
Joined
May 21, 2018
Messages
8,463
Or much, much, much better if the names included R2D2 you could do
If me.controls("ctrlR2D2"&i)
In other words what is your point?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:10
Joined
May 7, 2009
Messages
19,175
what do you mean by Tab? the form is Tabbed form or the control is in the Tab control?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 14:10
Joined
Jul 9, 2003
Messages
16,245
I agree with arnelGP, you haven't provided enough information to effect a reasonable answer to your question.

If you do mean each controls tab order, then I believe there is a way to navigate them in order.

However, the code example you have provided is puzzling. How do you initiate this code on its first iteration? How would you then run the code for the second iteration and so on?

Your question needs clarifying before any attempt to write the code you require it is undertaken.
 

Users who are viewing this thread

Top Bottom