can u help me about this . . .
when i click the column header of datagrid it will sort automatically

Do you have any code on the datagrid?

Or just by clicking on the column header automatically sorts your records?

yes, just by clicking the column header

Get the column that the user clicked on to get the database field value. Now reload the grid with the data sorted as per the users selection.

rs.Open "SELECT * FROM MyTableName ORDER BY " & "'" & UserValueChosen & "'"
Set Datagrid1.Datasource = rs
rs.Open "SELECT * FROM List ORDER BY " & "'" & UserValueChosen & "'"

Show me all the code you have to determine on which column you have clicked and then the code to open the recordset and re-populate the grid,

i dont understand,

Dim rstInfo As New ADODB.Recordset
Dim SQL As String

Call CON

SQL = "SELECT * FROM List"

    rstInfo.Open SQL, CN, adOpenStatic, adLockOptimistic
        
        rstInfo.AddNew


            rstInfo!CustomerName = txtName.Text
            rstInfo!ContactNumber = txtContact.Text
            rstInfo!Date = dt.Value
            rstInfo!TimeStart = cmbStart.Text
            rstInfo!TimeEnd = cmbEnd.Text
            rstInfo!Event = cmbEvent.Text
            rstInfo!Guest = txtGuest.Text
            rstInfo!Comment = txtComment.Text
    
    rstInfo.Update
    
         MsgBox "Record has been Saved", vbInformation
    
    frmList.Adodc.Refresh
    frmList.DataGrid.Refresh
    
    rstInfo.Close
CN.Close
Set rstInfo = Nothing

Your code above is to add a new record. What code are you using to populate the datagrid with your data? Are you using a datacontrol or code?

data control

The data control will not work. You need to set the grid's datasource AFTER you select the order by -

Dim conn as ADODB.Connection
Dim Rs As ADODB.Recordset
 
Set conn = new ADODB.Connection
Set Rs = New ADODB.Recordset
 
Conn.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\YourDatabaseName.MDB;Persist Security Info=False"

'Lets say the user selected column 3 on the datagrid, the fieldname in your table is say "Surname"

Rs.Open "SELECT * FROM MyTable ORDER BY Surname", conn, adOpenStatic, adLockOptimistic
 
Set Datagrid.DataSource = Rs
Private Sub DataGrid_Click()

This is not helping a lot. Show me the code and not a picture. With the code I can see why you got an error. The picture can be an error of multiple things.

The main thing is that it is looking for a function that you are calling, wich is non existent.:)

Private Sub DataGrid_Click()
Dim conn As ADODB.Connection
Dim Rs As ADODB.Recordset
 
Set conn = New ADODB.Connection
Set Rs = New ADODB.Recordset
 
conn.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database1.MDB;Persist Security Info=False"

'Lets say the user selected column 3 on the datagrid, the fieldname in your table is say "Surname"

Rs.Open "SELECT * FROM List ORDER BY CustomerName", conn, adOpenStatic, adLockOptimistic
 
Set DataGrid.DataSource = Rs
End Sub

Did you set a reference to MS Active X Data Objects x?

I think that might be the problem.

how can i do that?

Click on "Project/References and scroll down to "Microsoft Active X Data Objects 2.x Library" The x in 2.x is your latest version on your computer.

here

Yes, it seems you have version 2.0 installed. Select it and click OK. You do not need the MS Databinding collection as yet.

then? what should i do next

Now, use the code....

when i click list

I see. change "conn.Open = "...." to conn.Open "...." remove the equal sign.

it doesn't have error anymore but when i click the column header it doesn't sort and if i click other column header the records will disappear

The code that I supplied above must be under the data grid event, otherwise it will not work.

can you check my project?

Zip your app and add it here.

ok

Got it, will post here again once I see what you are trying to do.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.