Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2013
    Posts
    1

    Unanswered: Access data to be stored in Userform Listbox

    Hello All,

    Hope you all are doing great,

    This forum is really very great to help other,

    I have a code where I want the access table database to show it on the userform listbox in excel vba.

    however I m getting an error as file could not be found, checked the path as well but it doesn't resolved:

    My code goes here:
    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
    Many thanks in advance, if somebody can really help me.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Not sure it will change anything, but you could try:
    Code:
    "Data Source=E:\SAMI.accdb"
    Which version of Office do you use?
    Have a nice day!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •