Here is a quick example how to connect
to database and match block names
if you have the array of these blocks
' request reference to: Microsoft ActiveX Data Object 2.X Library
Sub CompBlockNames()
On Error GoTo ErrorHandler
' connection and recordset variables
Dim conn As ADODB.connection
Dim rst As ADODB.Recordset
Dim sqlStr As String
' open connection
Set conn = New ADODB.connection
With conn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Data Source") = "C:\Temp\Test.mdb" '<--full path to database file
.Open
End With
' open recordset
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient
' change the table name to your suit (I use MyTable)
sqlStr = "SELECT MyTable.blockname FROM MyTable" '<-- blockname is field name in this table
rst.Open sqlStr, conn, adOpenStatic, adLockReadOnly, adCmdText
Dim ar As Variant
'say here is a list of block names:
ar = Array("a", "b", "c", "d", "e", "f", "g", "h")
Dim i As Integer
Dim col As New Collection
For i = 0 To UBound(ar)
rst.MoveFirst
Do While Not rst.EOF
If rst!blockname = ar(i) Then '<-- if the match have found then collect it
col.Add ar(i)
End If
rst.MoveNext
Loop
Next
Dim vr As Variant
For Each vr In col
Debug.Print vr
Next
' clean up
rst.Close
conn.Close
Set rst = Nothing
Set conn = Nothing
Exit Sub
ErrorHandler:
If Err <> 0 Then
MsgBox Err.Source & " --> " & Err.Description, , "Error"
End If
End Sub
~'J'~