Answered by:
Store Images in OLEObjects and Display in Reports

Question
-
Hello everybody,
Well I am created an application which supports both databases SQL Server and MS Access 2010 as backend and make changes in the database without going to client, But I have to put my customers logo in every report, I have many customers and I have to store different images at different places. How can I store Image in a Field and restore it in reports. Which fields I should use in both databases... I found it OLEObject in MS Access and image in SQL Server....
Can anyone give me code to store image in database and restore in MS Access Report or Save image to a folder...
Please help me with this I need to update the application for SQL Server and I am stuck with this thing...
Thanking Everybody.
A response will be appriciated
Regards,
Wasif Shahid
Regards, Wasif Shahid ACCEDER software
Thursday, November 15, 2012 11:31 AM
Answers
-
Wasif Shahid wrote:
not yet...! working on it.. and if you have any sample of this kind of
database please tell me. I need to edit a file in a record I mean
1. Add new file in a column if it is blankWith the code I posted in my 2nd answer you can load any file into a
binary|OLEObject field, independent whether it is blank or not.2. if there is already a file delete it and update new one
Not necessary, see above.
3. and extract file in the same folder [...]
Extraction would be (aircode):
Dim Db As DAO.Database Dim Rst As DAO.Recordset Dim lngFSize As Long Dim Buffer() As Byte Dim strFile As String Set Db = CurrentDb Set Rst = Db.OpenRecordset("SELECT YourBinary FROM Tab1;") lngFSize = Nz(LenB(Fld), 0) ReDim Buffer(lngFSize) Buffer = Rst.Fields("YourBinary").GetChunk(0, lngFSize) Open "C:\YourBinary.bin" For Binary Access Write As #1 Put #1, , Buffer Close #1 Rst.Close Set Rst = Nothing Set Db = Nothing
[...] or View the picture in a report.
- Make sure the binary field is included in the report's recordsource.
- Add a bound object frame.
- Make Tab1 field YourBinary the control source of this bound object frame.
Peter Doering [MVP Access]
- Edited by Peter DoeringMVP Friday, November 30, 2012 11:55 PM Formatting
- Proposed as answer by Peter DoeringMVP Monday, December 3, 2012 12:11 AM
- Marked as answer by Dummy yoyo Monday, December 10, 2012 3:28 AM
Friday, November 30, 2012 11:54 PM -
Wasif Shahid wrote:
Well I tried it and It works fine... but now how to do it with SQL
Server??? I mean I tried it with Microsoft Access 2010 and it is working
fine. now how can I do it with SQL Sever???Re. ADO vs. DAO, if you have the choice you should go for DAO (ACEDAO).
Although still supported there is no more development on ADO.Re. howto and SQL Server: you should link the SQL Server tables and then
use the same code as for local tables. You can link tables through Ribbon
External Data - Import & Link - ODBC Database - <follow the wizard> or
through VBA:DoCmd.TransferDatabase acLink, "ODBC Database", _
"ODBC;Driver=SQL Server;Server=YourServer;Database=YourDB;" & _
"Uid=you;Pwd=secret;", acTable, _
"YourServerTableName", "YourLocalTableName", , TrueUsually server and local table names are identical.
Peter Doering [MVP Access]
- Marked as answer by Dummy yoyo Monday, December 10, 2012 3:28 AM
Saturday, December 1, 2012 10:52 PM
All replies
-
Wasif Shahid wrote:
Well I am created an application which supports both databases SQL
Server and MS Access 2010 as backend and make changes in the database
without going to client, But I have to put my customers logo in every
report, I have many customers and I have to store different images at
different places. How can I store Image in a Field and restore it in
reports. Which fields I should use in both databases... I found it
OLEObject in MS Access and image in SQL Server....
Can anyone give me code to store image in database and restore in MS
Access Report or Save image to a folder...Until 2003 (maybe 2007) you can store the picture in a field of type OLE
Object. In forms and reports you can add a bound object frame that uses the
field as control source.Since Access 2010 (maybe already 2007) it is possible to set the control
source of an image control to a path\picture.png (or jpg/bmp), no need to
store within the accdb anymore.Please help me with this I need to update the application for SQL Server
and I am stuck with this thing...On SQL Server the relevant field type is image.
Peter Doering [MVP Access]
Thursday, November 15, 2012 1:58 PM -
but I need to store the image in OLE Object and retrieve/display it on the report....! and I have to do it in the Runtime Mode so there will be no right click... That's why I need a VBA code to store and restore the image.
Regards, Wasif Shahid ACCEDER software
Thursday, November 15, 2012 3:00 PM -
Wasif Shahid wrote:
but I need to store the image in OLE Object and retrieve/display it on
the report....! and I have to do it in the Runtime Mode so there will be
no right click... That's why I need a VBA code to store and restore the image.You can store the image using AppendChunk. Here's a sample (aircode):
Dim Rst As DAO.RecordSet Dim Fld As DAO.Field Dim Buffer() As Byte Dim lngSize As Long Set Rst = CurrentDb.OpenRecordset("SELECT YourBinary FROM Tab1;") Open "C:\Temp\Your.jpg" For Binary Access Read Lock Read Write As #1 lngSize = LOF(1) ReDim Buffer(1 To lngSize) Get #1, , Buffer Close #1 Rst.Fields("YourBinary").AppendChunk Buffer Rst.Close Set Rst = Nothing
I'm sure you know how to setup error handling etc.
Peter Doering [MVP Access]
- Proposed as answer by Peter DoeringMVP Monday, December 3, 2012 12:11 AM
Thursday, November 15, 2012 6:22 PM -
Well thanks for your reply I got this article for me I hope this will also help me.
http://support.microsoft.com/kb/185958
the only thing now I am stuck with is that if I need to overwrite the data or delete the previous picture and store a new one how can I do it.. I am asking about editing not delete and add new record.
Regards, Wasif Shahid ACCEDER software
Friday, November 16, 2012 10:16 AM -
Wasif Shahid wrote:
Well thanks for your reply I got this article for me I hope this will
also help me.
http://support.microsoft.com/kb/185958This sample appends with a maximum block size, given the nature of Oracle.
Within Access and SQL Server you shouldn't have to slice the file.the only thing now I am stuck with is that if I need to overwrite the
data or delete the previous picture and store a new one how can I do
it.. I am asking about editing not delete and add new record.If you write a new picture your previous one will be overwritten. If you
just want to erase the existing picture:Rst.Fields("YourBinary").Value = Null
Peter Doering [MVP Access]
Friday, November 16, 2012 9:17 PM -
well I have changed some of the code for SQL Server and Microsoft Access
Thanks
but the second thing
Rst.Fiels("YouBinary").Value = null
dosent seems to work it gives errors....
Regards, Wasif Shahid ACCEDER software
Sunday, November 18, 2012 3:27 PM -
Sunday, November 18, 2012 10:17 PM
-
I am sorry sir, I am a little busy at this time. I'll response you when I reopen the project again... I will post very soon... may be on Tuesday...! I'll check the error and let you know.
Thanks...
Regards, Wasif Shahid ACCEDER software
Thursday, November 22, 2012 6:51 PM -
So have you got any update on this project?
Thanks.
Yoyo Jiang[MSFT]
MSDN Community Support | Feedback to us
Thursday, November 29, 2012 6:34 AM -
not yet...! working on it.. and if you have any sample of this kind of database please tell me. I need to edit a file in a record I mean
1. Add new file in a column if it is blank
2. if there is already a file delete it and update new one
3. and extract file in the same folder or View the picture in a report.
How to do it? I don't know how to use OLEObjects, I was working on attachment fields and now started using sqlsever so have to use oleobjects. how to do it???
Regards, Wasif Shahid ACCEDER software
Friday, November 30, 2012 9:48 PM -
Wasif Shahid wrote:
not yet...! working on it.. and if you have any sample of this kind of
database please tell me. I need to edit a file in a record I mean
1. Add new file in a column if it is blankWith the code I posted in my 2nd answer you can load any file into a
binary|OLEObject field, independent whether it is blank or not.2. if there is already a file delete it and update new one
Not necessary, see above.
3. and extract file in the same folder [...]
Extraction would be (aircode):
Dim Db As DAO.Database Dim Rst As DAO.Recordset Dim lngFSize As Long Dim Buffer() As Byte Dim strFile As String Set Db = CurrentDb Set Rst = Db.OpenRecordset("SELECT YourBinary FROM Tab1;") lngFSize = Nz(LenB(Fld), 0) ReDim Buffer(lngFSize) Buffer = Rst.Fields("YourBinary").GetChunk(0, lngFSize) Open "C:\YourBinary.bin" For Binary Access Write As #1 Put #1, , Buffer Close #1 Rst.Close Set Rst = Nothing Set Db = Nothing
[...] or View the picture in a report.
- Make sure the binary field is included in the report's recordsource.
- Add a bound object frame.
- Make Tab1 field YourBinary the control source of this bound object frame.
Peter Doering [MVP Access]
- Edited by Peter DoeringMVP Friday, November 30, 2012 11:55 PM Formatting
- Proposed as answer by Peter DoeringMVP Monday, December 3, 2012 12:11 AM
- Marked as answer by Dummy yoyo Monday, December 10, 2012 3:28 AM
Friday, November 30, 2012 11:54 PM -
I have to work on this with Microsoft Access 2010 database and SQL Server. so can I use ADO instead of DAO. because I can connect with SQL Server with ADO???
Regards, Wasif Shahid ACCEDER software
Saturday, December 1, 2012 1:05 PM -
Well I tried it and It works fine... but now how to do it with SQL Server??? I mean I tried it with Microsoft Access 2010 and it is working fine. now how can I do it with SQL Sever???
Regards, Wasif Shahid ACCEDER software
Saturday, December 1, 2012 4:13 PM -
Wasif Shahid wrote:
Well I tried it and It works fine... but now how to do it with SQL
Server??? I mean I tried it with Microsoft Access 2010 and it is working
fine. now how can I do it with SQL Sever???Re. ADO vs. DAO, if you have the choice you should go for DAO (ACEDAO).
Although still supported there is no more development on ADO.Re. howto and SQL Server: you should link the SQL Server tables and then
use the same code as for local tables. You can link tables through Ribbon
External Data - Import & Link - ODBC Database - <follow the wizard> or
through VBA:DoCmd.TransferDatabase acLink, "ODBC Database", _
"ODBC;Driver=SQL Server;Server=YourServer;Database=YourDB;" & _
"Uid=you;Pwd=secret;", acTable, _
"YourServerTableName", "YourLocalTableName", , TrueUsually server and local table names are identical.
Peter Doering [MVP Access]
- Marked as answer by Dummy yoyo Monday, December 10, 2012 3:28 AM
Saturday, December 1, 2012 10:52 PM