GetInfoFromDB module is for Get data from Access Database using VBA
Option Explicit
Sub GetInfoFromDB()
Dim Cn As New ADODB.Connection
Dim rec As New ADODB.Recordset
Dim strOut As String
With Cn
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data " _
& " Source=W:\YourAccessDataBAse.mdb;" _
& "Persist Security Info=False;"
.CursorLocation = adUseClient
.Open
End With
With rec
.Open "SELECT DISTINCT COUNTY " & vbNewLine _
& " FROM COP " & vbNewLine _
& " WHERE (COUNTY < 'BOONE') " & vbNewLine _
& " ORDER BY COUNTY", Cn
Do While Not .EOF
If Len(strOut) = 0 Then
strOut = !COUNTY.Value
Else
strOut = strOut & vbNewLine & !COUNTY.Value
End If
.MoveNext
Loop
.Close
End With
Set rec = Nothing
Cn.Close
Set Cn = Nothing
MsgBox strOut
End Sub