DevLSS
asked on
DAO Error 3001 Saving a byte array to ole object field
i am looping through a large amount of information stored in an Access 2003 DB and storing it into another DB.
The point of the process is to have the data saved back into the DB as a byte array.
This works fine 95% of the time, but there are cases where my code throw an error 3001 Invalid argument. Please see the code below:
Also is there a better way of doing this or a way to compress the Array so it take sup less space in the DB?
The point of the process is to have the data saved back into the DB as a byte array.
This works fine 95% of the time, but there are cases where my code throw an error 3001 Invalid argument. Please see the code below:
private sub MoveData
With rsSrc
If .RecordCount > 0 Then
.MoveLast
.MoveFirst
While Not .EOF
DoEvents
ReDim bArray(0)
strBuf = ""
If Not IsNull(!Data) And !Data.FieldSize > 0 Then
strBuf = !Data
' Save to array
bArray = StringToByteArray(strBuf)
rsDest.AddNew
rsDest!Date = !Date
rsDest!Data = bArray ' error 3001 here
rsDest.Update
End If
.MoveNext
Wend
End If
End With
end sub
Public Function StringToByteArray(varInput As Variant) As Byte()
' ***************************************************************************
' Routine: StringToByteArray
'
' Description: Converts a string of data into a byte array [Range 0, 255]
'
' Parameters: strInput - data string to be converted into a byte array
'
' Returns: Byte array
'
' ===========================================================================
' DATE NAME / eMAIL
' DESCRIPTION
' ----------- --------------------------------------------------------------
' 03-OCT-2000 Kenneth Ives kenaso@home.com
' Modified and documented
' ***************************************************************************
' ---------------------------------------------------------------------------
' Define local variables
' ---------------------------------------------------------------------------
Dim lngIndex As Long
Dim lngLength As Long
Dim bytBuffer() As Byte
Dim bytData() As Byte
' ---------------------------------------------------------------------------
' Store length of data string in a variable. Speeds up the process by not
' having to constantly evaluate the data length. Works great with loops
' and long strings of data. Good habit to get into.
' ---------------------------------------------------------------------------
lngLength = Len(varInput)
If lngLength < 1 Then
ReDim bytData(0)
StringToByteArray = bytData
Exit Function
End If
' ---------------------------------------------------------------------------
' Resize the array based on length on input string
' ---------------------------------------------------------------------------
ReDim bytBuffer(lngLength)
ReDim bytData(lngLength)
' ---------------------------------------------------------------------------
' Convert each character in the data string to its ASCII numeric equivalent.
' I use the VB function CByte() because sometimes the ASC() function returns
' data that does not convert to a value of 0 to 255 cleanly.
' ---------------------------------------------------------------------------
For lngIndex = 0 To lngLength - 1
bytBuffer(lngIndex) = CByte(Asc(Mid$(varInput, lngIndex + 1, 1)))
Next
' ---------------------------------------------------------------------------
' Copy data from memory to variable
' ---------------------------------------------------------------------------
CopyMemory bytData(0), bytBuffer(0), lngLength
' ---------------------------------------------------------------------------
' Return the byte array
' ---------------------------------------------------------------------------
StringToByteArray = bytData()
' ---------------------------------------------------------------------------
' Resize arrays to smallest size
' ---------------------------------------------------------------------------
ReDim bytData(0)
ReDim bytBuffer(0)
End Function
Also is there a better way of doing this or a way to compress the Array so it take sup less space in the DB?
ASKER
the string data is RTF formatted
Yeah. Why aren't you assigning it directly?
Is there some String simplification going on when you attempt that? (i.e. RTF formatting is lost? :-s)
With rsSrc
While Not .EOF
If Not IsNull(!Data) And !Data.FieldSize > 0 Then
rsDest.AddNew
rsDest!Date = !Date
rsDest!Data = !Data '<--- With the value assigned directly? String altered?
rsDest.Update
End If
.MoveNext
Wend
End With
Is there some String simplification going on when you attempt that? (i.e. RTF formatting is lost? :-s)
With rsSrc
While Not .EOF
If Not IsNull(!Data) And !Data.FieldSize > 0 Then
rsDest.AddNew
rsDest!Date = !Date
rsDest!Data = !Data '<--- With the value assigned directly? String altered?
rsDest.Update
End If
.MoveNext
Wend
End With
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That certainly falls into the category of "hard to diagnose remotely" ;-)
My question still stands though.
Cheers.
My question still stands though.
Cheers.
ASKER
because the data in the source is not in RTF format, and the destination must be in RTF format. Otherwise, yes, it would have been a no brainer. :-) Thanks for your help.
ASKER
i figured out the solution myself, it was a size issue with the destination DB
Why are you using an explicit Byte Array at all to perform this task?
I say explicit as strings are essentially that anyway, and you're bringing this data via a string - so it is clearly Unicode supported...
What sort of data is stored in this field?
Cheers.