• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Data not sent to Access database

Derek McGill

Active Member
All help will be welcome fixing macro which is to transfer a Table called "Look_up_Table2" to Access, Error is in reading first field name.
 

Attachments

  • Data.xlsm
    73.8 KB · Views: 7
No error msg just no data sent to Access.
When i go to Fld1 it skips to onError then back to Fld2 then to onError and so on.
 
No. If the header names match the field names in the database, why not just use them directly instead?

By the way, when you write this in VBA:

Code:
Dim Fld1, Fld2, Fld3, Fld4, Fld5, Fld6, Fld7 As String

only Fld7 is declared as a String, all the others are Variant. You have to specify the type for each variable.
 
Instead of this:

Code:
Fld1 = Range("FullName")
Fld2 = Range("Initial")
Fld3 = Range("Surname")
Fld4 = Range("Rating")
Fld5 = Range("Kfactor")
Fld6 = Range("PhoneNo")
Fld7 = Range("MobileNo")

use this:

Code:
Fld1 = "FullName"
Fld2 = "Initial"
Fld3 = "Surname"
Fld4 = "Rating"
Fld5 = "Kfactor"
Fld6 = "PhoneNo"
Fld7 = "MobileNo"
 
Jet has no clue about the accdb format. Change the provider to:

Code:
Provider=Microsoft.ACE.OLEDB.12.0
 
Comment out the On Error statement so that we can determine what the actual error message is.
 
Sorry for the delay.

There are a few changes required to your code and workbook.

First, your range needs to include the header row, so it should start at A1.

Second, sWbkName should include the extension, so:

Code:
sWbkName = ThisWorkbook.Name

Last, your connection to the workbook should specify Excel 12 format:

Code:
" [Excel 12.0;HDR=YES;Database=" & sThisWbk & ";].[MyRange];"
 
Thanks Debaser
Code working now.
I also had to change MyRange slightly by adding
Set Table1 = ActiveSheet.ListObjects("MyRange") into the code
Derek
 
Back
Top