GetInfoFromDB module is for Get data from Access Database using VBA

Code examples

0
0

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

Similar pages

Similar pages with examples

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................