+ Reply to Thread
Results 1 to 3 of 3

vba

  1. #1
    Registered User
    Join Date
    09-29-2015
    Location
    India
    MS-Off Ver
    2007
    Posts
    1

    vba

    i have a access database with table name employee details. I want to extract names of employees from table employee details where Degination of employee is AMO and trying to add the name of employee to a combo box but object required 424 error.plz find the code
    Dim cnn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim dbPath As String
    Dim SQL As String
    Dim i As Integer
    Dim var
    On Error GoTo errHandler:
    dbPath = "E:\office_hsbc\ofc.accdb"
    var = "AMO"
    Set cnn = New ADODB.Connection ' Initialise the collection class variable
    cnn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbPath
    cnn.Open
    SQL = "SELECT * FROM Employee_Details where DESIGNATION = '" & var & "'"
    Set rs = New ADODB.Recordset 'assign memory to the recordset
    rs.Open SQL, cnn

    'Check if the recordset is empty.
    If rs.EOF And rs.BOF Then
    'Close the recordet and the connection.
    rs.Close
    cnn.Close
    'clear memory
    Set rs = Nothing
    Set cnn = Nothing
    'Enable the screen.
    Application.ScreenUpdating = True
    'In case of an empty recordset display an error.
    MsgBox "There are no records in the recordset!", vbCritical, "No Records"

    Exit Sub
    End If

    'Write the reocrdset values in the sheet.
    For i = 0 To oRs.Fields.Count - 1
    comboamo.AddItem(i) = oRs.Fields(i).Name
    Next
    'Close the recordset and the connection.
    rs.Close
    cnn.Close
    'clear memory
    Set rs = Nothing
    Set cnn = Nothing

    'Enable the screen.
    Application.ScreenUpdating = True


    'Inform the user that the macro was executed successfully.
    MsgBox "Congratulation the data has been successfully Imported", vbInformation, "Import successful"
    'error handler
    On Error GoTo 0
    Exit Sub
    errHandler:
    'clear memory
    Set rs = Nothing
    Set cnn = Nothing
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Import_Data"


    kindly suggest solution

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,074

    Re: vba

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title go to your first post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Never use Merged Cells in Excel

  3. #3
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,074

    Re: vba

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1