+ Reply to Thread
Results 1 to 3 of 3

Thread: Runtime error 3024 could not find file

  1. #1
    Registered User
    Join Date
    09-14-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    1

    Runtime error 3024 could not find file

    Hello! I am a vb newbie and I would like to automate exporting excel files to my access database (multiple users will be using excel so as not to mess with my access database).

    I found the orig code on the net, tried manipulating it for my database but i keep getting run time error 3024 could not find file 'mydbfile.mdb'

    My file is there, and microsoft dao 3.6 object library has already been checked under my references.

    Kindly help? please...I am using excel and access 2007 (although i saved my database file as .mdb and my excel as .xlsm since i need userforms for my excel, because the multiple users cannot also manipulate the excel sheets manually because all data will be entered from the userforms only)

    Private Sub CommandButton1()
    Dim db As Database
    Dim rs As Recordset
    Dim r As Long
    Dim myDB As String
        
        myDB = "mydbfile.mdb"
    
        
        Set db = OpenDatabase(myDB)
        
        Set rs = db.OpenRecordset("exceltbl", dbOpenTable)
        
        ' get all records in a table
        r = 2 ' the start row in the worksheet
        Do While Len(Range("A" & r).Formula) > 0
        ' repeat until first empty cell in column A
            With rs
                .AddNew 
                .Fields("ID") = Range("A" & r).Value
                .Fields("FirstName") = Range("B" & r).Value
                .Fields("LastName") = Range("C" & r).Value
                .Fields("Section") = Range("D" & r).Value
                
                .Update
            End With
            r = r + 1 ' next row
        Loop
        rs.Close
        Set rs = Nothing
        db.Close
        Set db = Nothing
        
        MsgBox "Appended " & r - 1 & " Records to your database", vbOKOnly, "Confirmation"
    Range("B2:I205") = ""
    
    End Sub
    Last edited by teylyn; 09-14-2010 at 10:23 PM. Reason: added code tags

  2. #2
    Forum Guru
    Join Date
    10-28-2008
    Location
    Not here anymore
    MS-Off Ver
    irrelevant
    Posts
    10,150

    Re: Runtime error 3024 could not find file

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    I added code tags for you, but this time only!

  3. #3
    Valued Forum Contributor Norie's Avatar
    Join Date
    02-02-2005
    Posts
    512

    Re: Runtime error 3024 could not find file

    Your file is where exactly?

    You've only specified the filename, I think you need to specify the path too.

+ 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.2.0