Link to home
Start Free TrialLog in
Avatar of valhallatech
valhallatech

asked on

Transfer spreadsheet to SQL server cant append

Hi all - Im using vba to programmatically transfer a spreadsheet to sql server, from vba code in my adp file.

i.e. docmd.transferspreadsheet acImport, acSpreadsheetTypeExcel10, tableMyTable, pathToFile,true

Because it doesnt correctly determine the data types, I figured I'd create the table first, then use this to append the data, as the help file explicity tells me that Data will be appended if the table exists or a table will be created if not.

However I get an error "Run Time error 3146, ODBC call failed, There is an already an object named 'mytablename' in the database(#(2714)"

Is there a way I can use transferspreadsheet to append to my table?

Thanks

Avatar of infolurk
infolurk

What you state above should be correct. If the table exists the data should be written to it.
However, for whatever reason, this isnt happening.
If the table doesn't exist, does the import work? If so you could check for the table's existence and if it is there delete it then run the import.
Im not familiar with adp files, does this mean you arent running the import from in access? Also, are you importing directly to an SQL table linked via ODBC? These things might be causing your problem.

cheers
Steve
Avatar of rockiroads
I wonder if this is specific to ADP's. Certainly with MDB, u can quite happily write and append to tables

This table of yours, its created on SQL Server and u linked it in right? I dont believe u can create local tables on ADP.

Avatar of valhallatech

ASKER

rockiroads: correct - the table is stored in sql server - yes I 'connected' to it - the linked concept as exists in an mdb file doesnt exist in adp files. yes the table is mine. As for am i going via odbc - i dont know - I connect using the  connect option on the file menu - which I thought used OLEDB, and that this was different to odbc - certainly I dont have to set up a dsn for eg. - im puzzled that the error quotes as being an ODBC error

infolurk: Yes this works as file/Import  in the menus system (actually it didnt work, it failed due to other reasons - but it didnt complain about existance of table). I dont want to be deleteing the the table if I can, as I create it for the purpose of actually determining the data type.  

Have u tried prefixing the tablename with the owner?
e.g.   dbo.mytablename

ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

 have tried dbo

yeah - thought I'd try ado - in middle of giving it a go as we speak. god i hate access. seems to be working though.

I'll leave this open for a while longer to see if anyone can help me fix the problem 'properly' - and if nothing is forth coming give you the points for this.

Thanks for the link
Glenn