codice:
Dim strSQL As String, strConn As String
Dim Conn As ADODB.Connection, RS As ADODB.Recordset
Dim Output As Integer
strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=PathENomeDB.mdb"
Set Conn = CreateObject("ADODB.connection")
Conn.Open strConn
strSQL = "select top 1 id from dati where ora = '2' order by data desc"
Set RS = CreateObject("ADODB.Recordset")
RS.Open strSQL, Conn, 3, 3
Output = RS("id").Value
If IsObject(RS) Then
If Not RS Is Nothing Then
If RS.State = 1 Then RS.Close
Set RS = Nothing
End If
End If
Conn.Close
Set Conn = Nothing
questo è un esempio di connessione a un DataBase Access...
naturalmente devi cambiare il nome e la path del db e inserire Microsoft ActiveX Data Object nei riferimenti..