Datasheet Column reference help (1 Viewer)

Eightball3

Registered User.
Local time
Today, 00:14
Joined
Jun 30, 2010
Messages
18
This code will retrieve the column order of a specified control name:

Forms("frmMain").Controls("frmSub").Form.Controls("field_name").ColumnOrder

I would like to retrieve the control name if the column is specified. In the above example there is a main form and the subform is a datasheet.

Anyone able to help? Thanks:)
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 02:14
Joined
Feb 28, 2001
Messages
27,148
Enumerate via a For loop from 0 to ...controls.count - 1;

Test each control against the column order you were given.

When you find a match, the name is

Name = Forms("frmMain").Controls("frmSub").Form.Controls(index).Name

You can also do an Exit For when you find the matching number.
 

Eightball3

Registered User.
Local time
Today, 00:14
Joined
Jun 30, 2010
Messages
18
Thanks for the reply.

I'm using this to try and determine what order the columns have been set to by the user of a datasheet. Will your suggestion give me explicit name? It seems to be only giving me the name of the control that is positioned on the original saved subform?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 02:14
Joined
Feb 28, 2001
Messages
27,148
You didn't make that clear earlier. Are you saying that a user can "scramble" the order of the columns somehow? Please clarify.

I suspect that if that run-time scrambling is the case, you have to look at some other property - or perhaps some other object than the named datasheet. If it hasn't been saved yet, it might HAVE no name, in which case you can't find it by naming the sheet.
 

Users who are viewing this thread

Top Bottom