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
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!
Your file is where exactly?
You've only specified the filename, I think you need to specify the path too.![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks