Hello All,
Hope you all are doing great.
This is the code I have added to retrieve data from access to userform listbox
Where I am getting the error as file could not be found, However my file Path is correct.
Private Sub Access_to_database()
'Microsoft ActiveX Data Objects 2.8 Library-Activate
On Error GoTo UserForm_Initialize_Err
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.recordSet
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source = E:\SAMI.accdb"
rst.Open "SELECT (CSTName),(EmailSub) FROM SAMI_Data ORDER BY [EmailSub];", _
cnn, adOpenStatic
rst.MoveFirst
With Summary.Listbox1
.Clear
Do
.AddItem rst![CSTName]
rst.MoveNext
Loop Until rst.EOF
End With
UserForm_Initialize_Exit:
On Error Resume Next
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Exit Sub
UserForm_Initialize_Err:
MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error!"
Resume UserForm_Initialize_Exit
End Sub
It would be really appreciable if any1 can help me on the same.
Bookmarks