3
Contributors
27
Replies
30
Views
6 Years
Discussion Span
Last Post by AndreRet
0

Do you have any code on the datagrid?

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

0

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
0
rs.Open "SELECT * FROM List ORDER BY " & "'" & UserValueChosen & "'"
Attachments debug.JPG 62.52 KB
0

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,

0

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
0

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?

0

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
0

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.:)

0
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
0

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.

0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.