LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Array keeps returning Null Values

I am having trouble with the Array portion of the attached code - as I step
through it works fine until it hits where I am loading the Excel information
into the variable.
.Update VBA.Array("ID", "Fname", "Lname"), Array(vaData(i, 1),
vaData(i, 2), vaData(i, 3)) when I hover over vaData it will show me the
information from the cells but on the Next step I get an error Message
"Cannot insert the Value NULL into column ID, table
GPReports.dbo.My_Employees; column does not allow nulls. Insert fails. If I
were to remove restrictions from the table it post NULL in the row.

Here is the full code:
Sub Export_Data_Excel()

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:l23")

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

stDB = ThisWorkbook.Path & "\" & "FirstTry"

'Create the connectionstring
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:l23")
'vaData = Application.Transpose(rnData.Value)

cnt.Open stConn

'Open the recordset.
rst.Open "My_Employees", cnt, adOpenKeyset, adLockOptimistic,
adCmdTableDirect

'Read data, add new data and update the recordset.

For i = 1 To UBound(vaData)
With rst
.AddNew
.Update VBA.Array("ID", "Fname", "Lname"), Array(vaData(i, 1),
vaData(i, 2), vaData(i, 3))
End With
Next i
MsgBox "Successfully updated the table!", vbInformation

'Close recordset and connection.
rst.Close
cnt.Close

'Release objects from memory.
Set rst = Nothing
Set cnt = Nothing

'Clear inputrange.
rnData.ClearContents

'Restore the settings.
With Application
.Calculation = xlCalc
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub

Any ideas will be greatly appreciated.

Norma

 
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
Counting values in an array where value in one column is not null CW Excel Worksheet Functions 5 April 22nd 10 04:06 AM
How to return an array of values that are not zero/Null apache007 Excel Discussion (Misc queries) 9 May 15th 09 06:00 AM
How to return an array of values that are not zero/Null apache007 Excel Discussion (Misc queries) 0 May 8th 09 01:57 AM
Returning an array of unique values? Blue Max Excel Worksheet Functions 10 January 16th 08 02:51 AM
Array Pasted from One Worksheet Converts Null Values to Zeros BK Waas Excel Discussion (Misc queries) 0 November 22nd 06 05:21 PM


All times are GMT +1. The time now is 11:26 AM.

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"