get data from microsoft access
in mysql there are query like
select colomn, count(column) from table group by column
in i need to do the same thing using microsoft access in visual basic 6.0, because after that get the data plus the count result, i would like to use that count number to do some calculation, how am i going to do... anyone know the coding for it??
[347 byte] By [
sookfuny] at [2007-11-20 10:55:32]

# 3 Re: get data from microsoft access
Same type deal. Here's a text file that I had:
'Syntax:
RS.Open "Source" (a table or sql statement), "Connection", "Cursor Type", "Record Locking Type", "Type of Open" (Table, text, stored procedure, etc.
'Ex:
RS.Open "SELECT * FROM Table1;"
'The source is to select all fields and records from the table called "Table1"
'Ex:
RS.Open "SELECT * FROM Table1;", CN
'CN is your connection object to the database so it knows what database and location, etc.
'Ex:
RS.Open "SELECT * FROM Table1;", CN, adOpenKeyset
'There are 4 types of cursor types (CursorTypeEnum):
adOpenForwardOnly - Default. Uses a forward-only cursor. Identical to a static cursor, except that you can only scroll forward through records. This improves performance when you need to make only one pass through a Recordset.
adOpenDynamic - Uses a dynamic cursor. Additions, changes, and deletions by other users are visible, and all types of movement through the Recordset are allowed, except for bookmarks, if the provider doesn't support them.
adOpenKeyset - Uses a keyset cursor. Like a dynamic cursor, except that you can't see records that other users add, although records that other users delete are inaccessible from your Recordset. Data changes by other users are still visible.
adOpenStatic - Uses a static cursor. A static copy of a set of records that you can use to find data or generate reports. Additions, changes, or deletions by other users are not visible.
'Ex:
RS.Open "SELECT * FROM Table1;", CN, adOpenKeyset, adLockOptimistic
'There are 4 basic types of recordlocking:
adLockReadOnly - Indicates read-only records. You cannot alter the data.
adLockPessimistic - Indicates pessimistic locking, record by record. The provider does what is necessary to ensure successful editing of the records, usually by locking records at the data source immediately after editing.
adLockOptimistic - Indicates optimistic locking, record by record. The provider uses optimistic locking, locking records only when you call the Update method.
adLockBatchOptimistic - Indicates optimistic batch updates. Required for batch update mode.
'Ex:
RS.Open "SELECT * FROM Table1;", CN, adOpenKeyset, adLockOptimistic, adCmdText
'Options: A Long value that indicates how the provider should evaluate the Source argument
'There are a few options for Options: CommandTypeEnum -
adCmdText - Evaluates CommandText as a textual definition of a command or stored procedure call.
adCmdTable - Evaluates CommandText as a table name whose columns are all returned by an internally generated SQL query.
adCmdStoredProc - Evaluates CommandText as a stored procedure name.
adCmdUnknown - Default. Indicates that the type of command in the CommandText property is not known.
adCmdFile - Evaluates CommandText as the file name of a persistently stored Recordset. Used with Recordset.Open or Requery only.
adCmdTableDirect - Evaluates CommandText as a table name whose columns are all returned. Used with Recordset.Open or Requery only. To use the Seek method, the Recordset must be opened with adCmdTableDirect.
'And ExecuteOptionEnum -
adAsyncExecute - Indicates that the command should execute asynchronously.
adAsyncFetch - Indicates that the remaining rows after the initial quantity specified in the CacheSize property should be retrieved asynchronously.
adAsyncFetchNonBlocking - Indicates that the main thread never blocks while retrieving. If the requested row has not been retrieved, the current row automatically moves to the end of the file.
adExecuteNoRecords - Indicates that the command text is a command or stored procedure that does not return rows (for example, a command that only inserts data). If any rows are retrieved, they are discarded and not returned.
adExecuteStream - Indicates that the results of a command execution should be returned as a stream.
adExecuteRecord - Indicates that the CommandText is a command or stored procedure that returns a single row which should be returned as a Record object.
adOptionUnspecified - Indicates that the command is unspecified.
# 4 Re: get data from microsoft access
and some code:
Option Explicit
Private Sub Form_Load()
Dim dteDate As Date
Dim adoRec As ADODB.Recordset
dteDate = CDate("7 March 2005 10:04:00AM")
Set adoRec = GetRecordset(dteDate)
With adoRec
Do While Not .EOF
'your code goes here
MsgBox .Fields(0)
.MoveNext
Loop
.Close
End With
Set adoRec = Nothing
End Sub
Private Function GetRecordset(ByVal pdteSearchDate As Date) As ADODB.Recordset
Dim strSQL As String
Dim adoRec As ADODB.Recordset
strSQL = "SELECT * "
strSQL = strSQL & "FROM AS_Createsched "
strSQL = strSQL & "WHERE AS_Createsched.CSIN_dates = #" & Format$(pdteSearchDate, "d mmm yyyy") & "# "
strSQL = strSQL & "AND HOUR(AS_Createsched.CSIN_times) = " & Format$(pdteSearchDate, "hh") & " "
strSQL = strSQL & "AND MINUTE(AS_Createsched.CSIN_times) = " & Format$(pdteSearchDate, "nn") & " "
Set adoRec = New ADODB.Recordset
adoRec.Open strSQL, GetConnString, adOpenForwardOnly, adLockReadOnly
Set GetRecordset = adoRec
Set adoRec = Nothing
End Function
Private Function GetConnString() As String
GetConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db4.mdb;Persist Security Info=False"
End Function