ADODB Import fixedwidth - no value given for required parameters

ajaynon

New Member
Joined
May 23, 2011
Messages
1
Hi,

First of all let me preface this with: I've tried hard to find the answer to this myself, so I'm sorry if this already exists on the forum.

I'm trying to do a mass import into access using the OLEDB driver and "fixed width" if you notice in the below code, the commented out part is what I was using and this worked fine, but I want to avoid using a drop table command due to PEBKAC incase the table is dropped and excel randomly crashes, the user in this instance does not have access, and will not be able to recreate the table.

I've tried all kinds of combinations in my INSERT command and have played with the schema file to no avail. It gets stuck trying to execute the SQL saying "no value given for required parameters". I know there is something wrong with my syntax or schema file, I just don't know what.

Sample data also provided. Thanks in advance.

Code:
    Dim cn As ADODB.Connection ', Rs As ADODB.Recordset, r As Long
    Set cn = New ADODB.Connection
    cn.Mode = 3 ' adModeReadWrite
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=" & ActiveWorkbook.Path & "\base.mdb" '& ";Extended Properties=""text;HDR=NO;FMT=FixedLength"""
    cn.Execute "DELETE * FROM BASE;"
    SQLstring = "INSERT INTO [BASE] ([ignore], [MSN], [Service Status], [Product Plan], [Add Date], [Status Change], [Dealer Code], [Account Number]) SELECT F1, F2, F3, F4, F5, F6, F7, F8 FROM [Text;HDR=NO;DATABASE=" & ActiveWorkbook.Path & "].[BASE.TXT]"
    cn.Execute SQLstring

    'cn.Execute "DROP TABLE BASE;"
    'SQLstring = "SELECT * INTO [BASE] FROM [Text;DATABASE=" & ActiveWorkbook.Path & "].[BASE.TXT]"
    'cn.Execute SQLstring
    
    cn.Execute "DELETE * FROM  [BASE] WHERE BASE.[Account Number] Is Null or BASE.[Account Number] = 'C.ACCOUNT_NUMBER'"
    cn.Close
    Set cn = Nothing
Code:
Schema.ini contains:

[BASE.TXT]
ColNameHeader=False
MaxScanRows=0
CharacterSet=ANSI
Format=FixedLength
col1=ignore Text Width 1
col2=MSN Text Width 20
col3="Service Status" Text Width 19
col4="Product Plan" Text Width 22
col5="Add Date" DateTime Width 13
col6="Status Change" DateTime Width 23
col7="Dealer Code" Text Width 16
col8="Account Number" Text Width 18
Sample data in text file
Code:
 P.CELLULAR_NUMBER   C.SERVICE_STATUS   P.PRODUCT_PLAN_CODE   C.ADD_DATE   C.STATUS_CHANGE_DATE   C.DEALER_CODE   C.ACCOUNT_NUMBER  
 0999999999          A                  DOWTV1                 6/07/11      6/07/11               RS999           99999999          
 0999999999          C                  DOWTV1                30/03/11     20/12/11               RS999           99999999          
 0999999999          C                  DOWTV1                28/09/11     29/09/11               RS999           99999999          
 0999999999          A                  DOWTV1                10/03/11     10/03/11               RS999           99999999          
 0999999999          A                  DOWTV1                 4/08/11      4/08/11               RS999           99999999          
 0999999999          C                  DOWTV1                 8/06/11      7/11/11               RS999           99999999          
 0999999999          C                  DOWTV1                28/09/11     11/10/11               RS999           99999999
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,223,886
Messages
6,175,193
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top