?
Solved

Programmatically set column order in dataview

Posted on 2005-04-22
10
Medium Priority
?
819 Views
Last Modified: 2008-01-09
Is it possible to set the column order programmatically for a dataview?
I know I can set the order by dragging columns left or right and then save the view, but I want to do that programmatically.
0
Comment
Question by:Contento1
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 2

Expert Comment

by:nikkilocke
ID: 13842692
Hi Contento1,

What's a "dataview"?

If you mean a query, just specify the columns you want, in the order you want, in the query when setting it up.

Hope this helps,

Nikki
0
 
LVL 15

Expert Comment

by:Simon Ball
ID: 13842698
you could create a query with the fields in the order that you want.

you can even create this query programmatically using querydef create object.

i do not know how to change the order of fields in a table though
0
 
LVL 15

Expert Comment

by:Simon Ball
ID: 13842712
i think the daa view is where th form looks at a table, and the form is set to dataview mode.

change the form to look at a query instead of the base table,
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:Contento1
ID: 13842730
No, sorry, I meant i form in datasheet view.
0
 

Author Comment

by:Contento1
ID: 13842750
I should also shoul add that the order needs to depend on user input, i.e. the column order could be changed dynamically
0
 
LVL 15

Expert Comment

by:Simon Ball
ID: 13842762
yes.  whats the record source for the form?

is it a table or a query?

if you use a query you can specify the field order in the query ( as long as you don't use select * from table......)

and then the datasheet should use that order.

0
 
LVL 39

Accepted Solution

by:
stevbe earned 1200 total points
ID: 13842776
I have a full module that tracks what a user chnages the width and order of columns because runtime does not save trhe values for next time for them.

The specific properties you are looking for are ...

            .ColumnWidth  and  .ColumnOrder

Steve
0
 
LVL 16

Expert Comment

by:Chuck Wood
ID: 13842893
Hi Contento1,

Here is some sample code that might be what you are looking for:

' based on the value of a text box,
' (or could use an option group, etc.)
Select Case txtUserInput
    ' select which order you want for your list box
    Case "Name"
        ' set the list box row source with the order you want
        lstListBox.RowSource = "SELECT Name, Address, City FROM tblCustomers"
    Case "Address"
        lstListBox.RowSource = "SELECT Address, City, Name FROM tblCustomers"
    Case "City"
        lstListBox.RowSource = "SELECT City, Address, Name FROM tblCustomers"
End Select
' requery the list box to refresh the list
lstListBox.Requery

If you have any further questions on this, please let me know.

Regards,

Chuck
0
 

Author Comment

by:Contento1
ID: 13843040
I needed to set the datasheeet view, not a list box.

Thanks anyway Chuck
0
 
LVL 16

Expert Comment

by:Chuck Wood
ID: 13843178
Hi Contento1,

In that case, use something like this:

' declare a public variable in a module
Public strOrder As String

'=== somewhere in another form, create the order string

' in the Form_Load event,
Private Sub Form_Load
    Select Case strOrder
        ' select which order you want for your form
        Case "Name"
            ' set the list box row source with the order you want
            Me.RecordSource = "SELECT Name, Address, City FROM tblCustomers"
        Case "Address"
            Me.RecordSource = "SELECT Address, City, Name FROM tblCustomers"
        Case "City"
            Me.RecordSource = "SELECT City, Address, Name FROM tblCustomers"
    End Select
End Sub

I hope that meets your requirements.

Chuck
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question