Avatar of Dale Fye
Dale Fye
Flag for United States of America asked on

Export data from visible datasheet columns in order displayed

I've got a couple of forms which display data in subforms which display query results in a datasheet format.

I don't normally like datasheets, but my client has about a dozen people using this particular application, and each of them is only interested is about 10 of the 30 fields in this table.  So they wanted a way for their users to hide and rearrange the columns and the datasheet seemed like the most appropriate option.

Now they want their users to be able to export the filtered recordset that is currently displayed in the datasheet to an Excel spreadsheet, but they only want to display the fields that are visible in the subform, and they want them displayed in the column order the user has defined by dragging the columns.

So, I'm looking for a way to build a dynamic SQL string which selects only those fields that are displayed and in the order they are displayed.  I know I can use the columnHidden property of the controls collection to determine whether the column is visible or not.  But I've been unable to identify the appropriate property to loop through the collection and identify the sequence that they are displayed in, so I can build the SQL string.

Any ideas?
Microsoft Access

Avatar of undefined
Last Comment
Nick67

8/22/2022 - Mon
Rey Obrero (Capricorn1)


Dim ctl As Control
For Each ctl In Me.subformControlName.Form.Controls
    If ctl.ControlType = acTextBox Then
        If ctl.ColumnHidden Then
            Debug.Print ctl.Name
        End If
    End If

Next
Rey Obrero (Capricorn1)

oh, you  need the visible columns


Dim ctl As Control
For Each ctl In Me.subformControlName.Form.Controls
    If ctl.ControlType = acTextBox Then
        If ctl.ColumnHidden=0 Then
            Debug.Print ctl.Name
        End If
    End If

Next
SOLUTION
Rey Obrero (Capricorn1)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Dale Fye

ASKER
Cappy (It's Ray, right)?

I already had that part, what I'm trying to figure out is the sequence (left to right) of the columns, as they are displayed in the subform.

If possible, I'd prefer to iterate through these in sequence, but could create an array and populate the specific array element based on the displayed column sequence.  Then loop through the array to build the SQL string.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
Nick67

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Rey Obrero (Capricorn1)

i did not notice that it was you fyed,

there is the solution posted by Nick
Dale Fye

ASKER
Thanks, guys.  Precisely what I needed.

I so rarely use datasheets that this was really bugging me.  I knew there had to be a way to find this.
Nick67

No biggie.  Glad to help
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.