hi, anyone know of a while to open up a table in an access database and apply a filter and sort the data inside it. I am using this now
DoCmd.OpenTable "table_name", acViewNormal
but this doesn't seem to have the option of sorting or filtering data.
Thanks in advance.
Comments
:
: DoCmd.OpenTable "table_name", acViewNormal
:
: but this doesn't seem to have the option of sorting or filtering data.
:
: Thanks in advance.
:
:
Try using Open method for your ADODB command passing SQL string in the proper parameter
Dim strSQL As String
strSQL = "SELECT * FROM table_name WHERE field_name = parameter " & _
"ORDER BY parameter"
command.Open ConnectionString, strSQL
If you want to pass a parameter into the SQL statement, then just write the code as follows
strSQL = "SELECT ^ FROM table_name WHERE field_name = '" & _
field_name & "'"
If the field is numeric, leave off the ' from the string, if it is a date, then replace ' with #
Just fool around with it, if you need any more help, I can give a better code example, but this should be enough to get you started.
your code makes sense but that's not what i'm trying to do. I don't
want to end up with a recordSet. Instead I want to directly display
the table and let the user worry about processing the data; just as if you doubled click on a table inside access. Any idea!!
: thanks for the reply d3v1lman,,
: your code makes sense but that's not what i'm trying to do. I don't
: want to end up with a recordSet. Instead I want to directly display
: the table and let the user worry about processing the data; just as if you doubled click on a table inside access. Any idea!!
:
DoCmd object in Visual Basic? If I am not misstaken, you are using VBA not VB. If this is right, you are on wrong board. At the same time, using this object you can call ApplyFilter action. Not sure, but probaly that's what you are looking for.
: : thanks for the reply d3v1lman,,
: : your code makes sense but that's not what i'm trying to do. I don't
: : want to end up with a recordSet. Instead I want to directly display
: : the table and let the user worry about processing the data; just as if you doubled click on a table inside access. Any idea!!
Okay, another option is to use ADODC and DataGrid. Add both controls to a form, set the ConnectionString of the ADODC to the database, you can set AllowAddNew = True, if you choose, then set the CommandType to adCmdText, next, set the RecordSource = your SQL string (This is done in a Wizard), now all you do is set the DataGrid DataSource property = your ADODC. If you don't want them to navigate the grid using the ADODC, just set its visible property to false.
I hope I answered your question this time.