473,388 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

TransferSpreadsheet to .ADP dbo table

I'm getting a problem with importing an Excel spreadsheet into a table
in a SQL Server 2000 back-end. I'm doing this in VBA in an onClick
event proc in an Access 2003 project.

The target table's owner is 'dbo', but the database connection is via
user 'fred'. password 'bloggs' (say) using SQL Server authentication.
User 'fred' is a member of db_owner role.

What happens is that TransferSpreadsheet ignores the 'dbo' table and
creates a new version, owned by 'fred'. This has undesirable side-
effects downstream (the app crashes).

The TransferSpreadsheet (and spreadsheet file itself) seem to be fine,
as the data is imported OK when the existing target table is actually
owned by 'fred'.

Is there something (permission/grant?) that needs to be set to enable
'fred' to import into the 'dbo' table, or is there a problem with
TransferSpreadsheet?

Any help gratefully received!

Dave
Jun 27 '08 #1
5 4931
On May 8, 3:59 pm, D.St...@ed.ac.uk wrote:
I'm getting a problem with importing an Excel spreadsheet into a table
in a SQL Server 2000 back-end. I'm doing this in VBA in an onClick
event proc in an Access 2003 project.
Further info:

I thought it might help if I prefixed the target table name in the
TransferSpreadsheet call with 'dbo.', so the VBA line now reads:

DoCmd.TransferSpreadsheet acImport, , "dbo." & tempTab, strFilename,
True, "MyRange"

In fact, this gives an error (3078) because the table name generated
is 'dbo_mytab' instead of 'dbo.mytab'.

I also find that TransferText behaves the same, i.e. it creates a new
table belonging to 'fred' rather than use an existing one belonging to
'dbo'.

Cheers,

Dave
Jun 27 '08 #2
Hi Dave,

The TransferSpreadsheet command is fine. The problem is with the ADP.
TransferSpreadsheet would work more reliably with an MDB.

With the mdb you can easily read your excel data into a local table with
Transferspreadsheet and then push that data to the sql server using ADO.

I would recommend using a separate mdb for importing your excel data if
you want to stay with TransferSpreadsheet. Otherwise, I would recommend
stepping up to .Net for interfacing with sql server and excel (much
easier).

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #3
I connect SQL-Server and Excel this way:

1. I use the excel file as a linked server by running this Stored
Procedure (the parameter is the full path to the file):

CREATE Procedure [dbo].[LinkToOPEExcelFile]
@FileLocation nvarchar(255)
AS
IF EXISTS (SELECT srv.name FROM sys.servers srv WHERE srv.server_id !
= 0 AND srv.name = N'OPE_XLS')
EXEC master.dbo.sp_dropserver @server=N'OPE_XLS',
@droplogins='droplogins'

EXEC master.dbo.sp_addlinkedserver
@server = N'OPE_XLS',
@srvproduct=N'Excel',
@provider=N'Microsoft.Jet.OLEDB.4.0',
@datasrc=@FileLocation,
@provstr=N'Excel 8.0'

2. I create VIEW(s) accessing the table(s) resident in the XLS file
(one view):

CREATE VIEW [dbo].[North]
AS
SELECT *
FROM OPE_XLS...North$ AS North$_1

Now I can use the VIEW as the recordsource for forms or reports. An
advantage is that my data is now the data in the Excel file,
reflecting any change immediately.

Of course, I can make my own table with

"SELECT * INTO NorthSchools FROM North"

if I want the data to be static (not reflecting changes in the Execl
file).

TransferSpreadsheet is a powerful command. I would use it but I am not
sure that Access has kept it up=to-date as far as permissions go with
repect to folders and SQL_Server. An SQL-Server only solution seems
simpler and more likely to have no problems to me.
D.St...@ed.ac.uk wrote:
I'm getting a problem with importing an Excel spreadsheet into a table
in a SQL Server 2000 back-end. I'm doing this in VBA in an onClick
event proc in an Access 2003 project.

The target table's owner is 'dbo', but the database connection is via
user 'fred'. password 'bloggs' (say) using SQL Server authentication.
User 'fred' is a member of db_owner role.

What happens is that TransferSpreadsheet ignores the 'dbo' table and
creates a new version, owned by 'fred'. This has undesirable side-
effects downstream (the app crashes).

The TransferSpreadsheet (and spreadsheet file itself) seem to be fine,
as the data is imported OK when the existing target table is actually
owned by 'fred'.

Is there something (permission/grant?) that needs to be set to enable
'fred' to import into the 'dbo' table, or is there a problem with
TransferSpreadsheet?

Any help gratefully received!

Dave
Jun 27 '08 #4
On May 9, 2:58 am, lyle fairfield <lyle.fairfi...@gmail.comwrote:
I connect SQL-Server and Excel this way:

1. I use the excel file as a linked server by running this Stored
Procedure (the parameter is the full path to the file):

CREATE Procedure [dbo].[LinkToOPEExcelFile]
@FileLocation nvarchar(255)
AS
IF EXISTS (SELECT srv.name FROM sys.servers srv WHERE srv.server_id !
= 0 AND srv.name = N'OPE_XLS')
EXEC master.dbo.sp_dropserver @server=N'OPE_XLS',
@droplogins='droplogins'

EXEC master.dbo.sp_addlinkedserver
@server = N'OPE_XLS',
@srvproduct=N'Excel',
@provider=N'Microsoft.Jet.OLEDB.4.0',
@datasrc=@FileLocation,
@provstr=N'Excel 8.0'

2. I create VIEW(s) accessing the table(s) resident in the XLS file
(one view):

CREATE VIEW [dbo].[North]
AS
SELECT *
FROM OPE_XLS...North$ AS North$_1

Now I can use the VIEW as the recordsource for forms or reports. An
advantage is that my data is now the data in the Excel file,
reflecting any change immediately.

Of course, I can make my own table with

"SELECT * INTO NorthSchools FROM North"

if I want the data to be static (not reflecting changes in the Execl
file).

TransferSpreadsheet is a powerful command. I would use it but I am not
sure that Access has kept it up=to-date as far as permissions go with
repect to folders and SQL_Server. An SQL-Server only solution seems
simpler and more likely to have no problems to me.
Thanks for that Lyle - that sounds like a powerful technique I should
check out for the future. Unfortunately time constraints on the
current project mean I'm likely to have to use an ownership boj. Think
you may well be right about the Transfer commands not being squeaky
clean.

BTW, shouldn't the great .NET debate be continued on a different
group ;-)

Cheers,

Dave
Jun 27 '08 #5
>>Stupid and Lazy?

Well, I confess that I am not the brightest star in the sky - stupid?
hmmm - could be. Lazy? You betcha!!!

That is the beauty of .Net!!!!

It is precisely for the stupid and lazy. It makes us look like we are
the brightest starts in the sky. That is what I mean about easy.
Microsoft has taken the best elements of the Access paradigm and
integrated them into the .Net model. That is the whole point. You
think I can write complex MFC code (which is what Access and .Net are
all based on) ? You gotta be kidding! Well, actually, I have delved a
little into MFC (and Java and a few other technologies).

Access is still fundamentally a great tool. But it was just timne to
add OOP functionality to the model. How to do that? Build a whole new
model based on the old model. Adding OOP to the Access paradigm through
..Net has extended functionality by over 1000%, and .Net holds your hand
every inch of the way (well, at least VB.Net does - even C# to a
degree). It makes stupid guys look like they actually know what they
are doing. Between the .Net Error catching engine (which will slap your
hand every inch of the way and point out suggested fixes on the spot)
and the encapsulation of tons of API code, .Net reduces spaghetti code
significantly. STuff that could take 100 lines of code in VBA may take
only 10 lines in VB.Net (or even C# - well maybe 20 lines in C#).

AS for Transfer spreadsheet, one other trick would be to try automation.
You can use the Excel UsedRAnge property of the range object to read the
contents of the used range. This is kind of what TransferSpreadhsset
does. Then you can loop through the range object (from access) and read
each value of each row into a string and write that row to a table using
an ADO command object - something like this:

(make a reference to the Excel library)
Dim xl as New Excel.Application, wb as Excel.WorkBook, Sht as
Exce.WorkSheet, rng AS Excel.Range
dim cmd As New ADODB.Command, str1 AS String
Dim i As Integer, j As Integer

cmd.ActiveConnection = "..."

Set wb = xl.Workbooks.Open(...)
Set sht = wb.Sheets("Sheet1")
set rng = sht.UsedRange
For i = 1 to rng.rows.count
For j = 1 to rng.Columns.Count
if str1 <"" Then str1 = str1 & ", "
str1 = str1 & rng(i, j)
Next
cmd.CommandTExt = "Insert into your tbl Select " & str1
cmd.Excecute
Next
cmd.ActiveConnection.Close

In .Net you would use an OleDB DataAdapter and a SqlDataAdapter (these
are components of ADO.Net) to read from Excel and write to the Sql
Server DB. There is no looping involved which is similar to
TransferSpreadsheet which does not use looping - just a big data push.
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: gwaddell | last post by:
I have a stored procedure that is loading data into a global temp table. Here is all the code for that stored procedure. CREATE PROCEDURE AS SET NOCOUNT ON BEGIN
1
by: Nathan Bloom | last post by:
Hi, I have a procedure that transfer data from an Excel spreadsheet to an Access 2000 table. There is a start date and an end date in the range specified. One of the date fields transfers...
3
by: user_5701 | last post by:
Hello, I'm getting an error with a Docmd.Transferspreadsheet line of code: DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel2000, "tblTest", pathAndFilename, True The above line...
6
by: syvman | last post by:
Hi everyone... I am pulling my hair out trying to do this, and was wondering if someone could give me some assistance... I have an Excel spreadsheet containing several worksheets. I'd like to be...
10
by: ineedahelp | last post by:
Can anyone help me figure out why I continue to get a runtime error '3010' "TABLE qryMultiSelect ALREADY EXISTS'? Here is my code. thank you in advance for any help!!! Private Sub...
2
by: RZ15 | last post by:
Hi, I am trying to use the transferspreadsheet command to transfer a table into an excel file i have. I'm using the following code: Private Sub cmdOK_Click() 'Run Make-Table query...
3
by: Icarus | last post by:
I'm using TransferSpreadsheet to import an Excel file in to MS Access 2003. DoCmd.TransferSpreadsheet acImport, 8, strTable, strFileName, True, "" One of the columns in the Excel file is a...
7
by: franc sutherland | last post by:
Hi everyone, I am using Access 2003. I have a database with a table in it which is linked to an excel spreadsheet. When I install the database on someone else's system, the pathname to the...
6
by: provor | last post by:
Hello, I have the following code that I am using when a user presses a button to import an excel file into a table. The code is hard coded to point to the correct table. This works great for this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.