Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Passing Excel Values back to a SQL Table

I would like to send rows of Excel data back to an existing table. What kind
of query do I need to write - could you direct me to an example.

Thanks

normad
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default Passing Excel Values back to a SQL Table

Following list details how to export to an access database
http://www.excelkb.com/article.aspx?...0&cNode=1I7C3V

"NormaD" wrote:

I would like to send rows of Excel data back to an existing table. What kind
of query do I need to write - could you direct me to an example.

Thanks

normad

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Passing Excel Values back to a SQL Table

Steve: I am stuck on an error message at the part where we are building the
array. When I look at vaData1 it has the correct information, vaDate2 also
has the correct information to be passed back to the DB. It does add a new
row to my table with with null values in both fields. The Error message I
received is "Identity cannot be determined for newly inserted rows". I am
attaching the code up to the point where it says successful - If you have any
suggestions I will appreciate it.

Thanks

normad

Sub Export_Data_Access()

Dim cnt As ADODB.connection
Dim rst As ADODB.recordset
Dim xlCalc As XlCalculation
Dim rnData As Range, rnCell As Range
Dim stDB As String, stConn As String
Dim vaData As Variant
Dim i As Long

'Change settings in order to increase the performance.
With Application
xlCalc = .Calculation
.Calculation = xlCalculationManual
.EnableEvents = False
.ScreenUpdating = False
End With

Set rnData = ActiveSheet.Range("J21:M21")

'Instantiate the ADO COM's objects.
Set cnt = New ADODB.connection
Set rst = New ADODB.recordset

stDB = ThisWorkbook.Path & "\" & "First Try"

'Create the connectionstring - The database is protected with a password.

stConn =
"Provider=SQLOLEDB;Server=CorpDyndb;Trusted_Connec tion=Yes;Initial
Catalog=GPReports;UID=;"

'Populate the array with data from the range.
vaData = rnData.Value

'If the data is stored in rows instead of columns then the
'solution would be the following:
Set rnData = ActiveSheet.Range("j21:k21")
'vaData = Application.Transpose(rnData.Value)

'Create the connection.

cnt.Open stConn
'Open the recordset.

rst.Open "Employees", cnt, adOpenKeyset, adLockOptimistic, adCmdTableDirect

THIS IS MY PROBLEM !!
'Read data, add new data and update the recordset.
For i = 1 To UBound(vaData)
With rst
.AddNew
.Update VBA.Array("ID", "Fname"), VBA.Array(vaData(i, 1), vaData(i, 2))
End With

Next i

MsgBox "Successfully updated the table!", vbInformation

"steve_doc" wrote:

Following list details how to export to an access database
http://www.excelkb.com/article.aspx?...0&cNode=1I7C3V

"NormaD" wrote:

I would like to send rows of Excel data back to an existing table. What kind
of query do I need to write - could you direct me to an example.

Thanks

normad

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
calling a C++ program from Excel 2000 and passing a result from C++ back to an excel spreadsheet ellis kurland Excel Discussion (Misc queries) 3 August 15th 05 04:10 PM
Passing Strucutres from VBA to DLL and back mikeduk Excel Programming 1 August 7th 05 02:50 PM
Passing array from 2nd sub back to first sub ExcelMonkey[_190_] Excel Programming 2 March 14th 05 06:09 PM
Passing data back from a form Taras Excel Programming 0 November 24th 03 04:33 PM
Passing data back from a form Tom Ogilvy Excel Programming 0 November 24th 03 04:27 PM


All times are GMT +1. The time now is 06:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"