Private Sub UserForm_Initialize()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.RecordSet
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\My Folder\MyDatabase.mdb;User Id=admin;Password=;"
cn.Open strConn
rs.Open "Select * From ClientNames ORDER By Pname", cn, adOpenDynamic, adLockOptimistic, adCmdText
ListBox1.Clear
Do Until rs.EOF
ListBox1.AddItem rs, rs.Fields("PName").Value
rs.MoveNext
Loop
rs.Close
cn.Close
End Sub
|