Any one know what the max size of an ole object field is in Access. My program (beacons) program works until I try to read a large file into th database, then I get an "E_Fail" error from the provide. I dont even know what an E_Fail error is?
I found the problem, or at least a simple solution. I tried the exact same code, but instead used DAO as the database driver and guess what it worked fine. So it seems that the problem is in the ADO driver, not the size of the field (although there is a1 GB limit as you mention). Also I found a clever way with the help of your code to not only store any file the database, but also view any file in the OLE Container field once it is stored as long binary data in the database (I am doing this so any file can dropped into my OLE box can be stored then viewed later.
The problem I found with storing long binary data is that unless you know the type, you just have binary data, i.e. you dont know what kind of file it is. This poses a problem when trying to view ANY file that is stored as long binary data.
The method is simple, use the ole box to do the dirty work. When some one drops an object into the ole box, have the ole box 'SavetoFile'. By doing this, eveything is stored in the binary data, including the object header (now we will always know the type of file stored.) Once the ole box savetofile method has been completed, read the saved file into the database as long binary data using the appendchunk method as you showed. To view any object, Simple write the data from the long binary field to a file named .OLE, and use the ole box's readfromfile method. This method allows the ole box to do all the hardwork and the programmer does not have to worry about storing a file extension or object type with the long binary data. Hope this helps and if any needs the code, I will provide it.
Here it is. It needs cleaned up but it works. Let me know if you have questions.
Code:
Dim RS As ADODB.Recordset
Dim db As Database
Dim rsdao As Recordset
Private Sub Form_Load()
ConnecttoDB 'connection function for ado stuff
Set RS = New ADODB.Recordset 'Ado rs
RS.Open "Select * from tblTemp", NRGConnection, adOpenDynamic, adLockOptimistic, adCmdText
Set db = OpenDatabase(App.Path & Nuregdbname)
Set rsdao = _
db.OpenRecordset("Select * from tbltemp", _
dbOpenDynaset)
'tblTemp contains an ole field named "Longdata"
End Sub
Private Sub Save_Object_to_Recordset()
'Save object in the ole box to the rs
Dim bytData() As Byte
Dim strDescription As String
Dim FileNum As Integer
On Error GoTo err
Dim t As String
t = "c:\t.ole"
If Len(Dir(t)) > 0 Then
Kill t
End If
' Get file number.
FileNum = FreeFile
' Open file to be saved.
Open t For Binary As #FileNum
' Save the file.
OLE1.SaveToFile FileNum 'Save ole object to file
' Close the file.
Close #FileNum
Open t For Binary As #1 'Open saved file
'Get data from saved file
ReDim bytData(FileLen(t))
Get #1, , bytData 'Get data
Close #1
'Put in rs at current row
With rsdao
.Edit
.Fields("LongData").AppendChunk bytData
.Update 'ADO fails here for large files.
End With
Exit Sub
err:
MsgBox err.Description & " " & err.Number
err.Clear
End Sub
Public Sub Display_Ole_Object_From_Recordset()
Dim imgsze As Long
Dim offset As Long
Dim chunk() As Byte
Dim file As Integer
Const ChunkSize = 32768
Dim FileNum As Integer
Dim t As String
'Make sure the temporary file does not already exist
t = "c:\t.ole"
If Len(Dir(t)) > 0 Then
Kill t
End If
'Open temp file and write the db contents
file = FreeFile
Open t For Binary As #file
imgsze = RS("longdata").ActualSize 'Get field size from rs
Do While offset < imgsze
chunk() = RS("longdata").GetChunk(ChunkSize) 'Extract the data
Put #file, , chunk()
offset = offset + ChunkSize
Loop
Close #file
' Get file number.
FileNum = FreeFile
' Open file to be read by the ole
Open t For Binary As #FileNum
' Save the file.
OLE1.ReadFromFile FileNum 'Insert file into ole box
' Close the file.
Close #FileNum
MsgBox "Object inserted."
End Sub
"Any one know what the max size of an ole object field is in Access. My program (beacons) program works until I try to read a large file into th database, then I get an "E_Fail" error from the provide. I dont even know what an E_Fail error is?"
The answer is you need to go get ADO 2.7 Library from microsofts website!
Originally posted by Beacon Nah got me mate megatron to do that i just said delete all jethro's posts and he said ok!
So that's why all my threads have disappeared, including the one detailing how to export data at the speed of light....damn hope l keeped some notes on that one
I just got an unspecified error!!!! on the following code:
Why???
Code:
Dim db As Connection
Dim rs As Recordset
Private Sub LoadDriverBase()
Dim db As Connection
Set db = New Connection
db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Drivers\DriverBase\DrBase.mdb;Persist Security Info=False"
Set rs = New Recordset
rs.Open "Select * From Zipped", db.ConnectionString, adOpenStatic, adLockOptimistic
End Sub
Public Sub FillFields()
If Not (rs.BOF And rs.EOF) Then
txtDescription.Text = rs.Fields("Description")
txtfilename.Text = rs.Fields("filename")
End If
End Sub
Private Sub cmdAdd_Click()
Dim bytData() As Byte
Dim strDescription As String
'On Error GoTo err
With dlgadd
.Filter = "All Files (*.*|*.*"
.DialogTitle = "Select File"
.ShowOpen
Open .FileName For Binary As #1
ReDim bytData(FileLen(.FileName))
If FileLen(.FileName) > "1000000" Then
MsgBox "This is a large file it could take some time! Please be patient!!!", vbInformation, "Large File"
End If
End With
Get #1, , bytData
Close #1
Dim fn As String
fn = dlgadd.FileName
strDescription = InputBox("Enter description.", "New Zipped File")
With rs
DoEvents
Me.MousePointer = 11
.AddNew
.Fields("FileName") = fn
.Fields("Description") = strDescription
.Fields("Zipped").AppendChunk bytData
.Update
DoEvents
End With
Me.MousePointer = 0
'FillFields
Exit Sub
err:
If err.Number = 32755 Then
Me.MousePointer = 0
Else
Me.MousePointer = 0
MsgBox err.Description
err.Clear
End If
End Sub
Private Sub Form_Load()
LoadDriverBase
End Sub
Oh also note that code is for ADODB? Not dao not that it should matter but there maybe some functions in there that dao wont like!
It was an extension of my image_library one!
The Field name is correct, and I am using ADODB...
The library I am using is the Microsoft ActiveX Data Objects 2.1 Library. Could you attach the latest library to your next post... Maybe that's the problem.
Also, if you have time...
Could you put together a 'very simple' (I don't want to waste your time) sample program that will put .exe's into a dbase...
As you can see, I've tried to do this with the code posted here, but I've been quite unsuccessful as of yet.
This example was from when i was working out how to do it so it's real crap and basic. It works however but it's slow, looks crap and even the database is real simple.
I dont like posting stuff that aint up to standard but i dont have time to write comments and stuff for a more complex one!
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Does it mean that with your codes to save any files to database that I can do the following:
First of all, the user selects a file from a server and can insert the selected file into an attribute in the database. And that after insterting the file into the database, the user can in the future work on the file that is in the database? When the file is open for editing, it is not longer reflected/updated to the file in the server? Which means, the file in the database is no longer asociated/linked to the file in the server.
Can the codes that you've written support that? Hope you're able to understand what i'm talking about =)
Originally posted by Beacon Ok sorry bit lost what do you want to do??
You want to identify that it's an MP1 file yes/no?
later
b
I was looking at the second chunk of coding at the top - said mp1 in the code and I couldn't see where it was defined. Just did a search though for mp1 and you've stated its a Media Player control sooooooooooo Sorry
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
do i save all the information by using Appendchunk method? how do i get back my image after its saved to the database? can you show me the codes to do it?
First of all, that is some awesome code!!! It's going to help me a lot... and thnx for the example, I checked it out and it's cool (I'll examine what I did wrong in a little bit)
Thanks a million,
Squirrelly1
Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?
Beacon,
I was wrong, the example didn't exactly work for me.... I created a test .txt file and put some string into it... I think it was "This is a test" or something like that.... I had no trouble getting it into the database, but when I tried to save it to another name from the database, it gave me an error...
Code:
Either BOF or EOF is true.... la di da di da
the error was in the savefile sub on this line...
Code:
imgsze = rs("file").ActualSize
I checked out the created file anyway, and it was empty instead of containing my string...
Nope i havent tried streaming it! I wondered that myself but havent had the time to test it.
Over the next few days i'll see what i can do if i have time!
Ok it has no checks in it for eof or nothing i dont think.
The codes doesnt work if you loop the savefile sub but i dont think you doing that.
Though you may be at the EOF so you'll need to make sure the recordset is at the record you want.
Are you using the code in that attachment??
If so gimme 45mins and i'll be able to download it and test it.
How do I update the field that is of OLE Object datatype?
Do I have to delete the content in there first and then insert it in?
I'm doing the sql code wrongly...and it is deleting the record instead of just the content in the field.
Here's my sql code for that:
sql = "DELETE FileInfo.Comments FROM FileInfo WHERE FileInfo.FileName = '" & selectedFile & "'"
Or can I do it this way? Its wrongly done too...
sql = "UPDATE FileInfo SET Comments = " & "rst.Fields(Comments).AppendChunk strdata " & "WHERE FileInfo.FileName =" & selectedFile
Can you please help me with this? Thank you very much!