To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier

Reply Post New Thread
 
Thread Tools Display Modes
Old Jun 27th, 2005, 02:49 PM   #1
ultra2
Lively Member
 
Join Date: Jun 05
Posts: 81
ultra2 is an unknown quantity at this point (<10)
Obtain the picture from an OLE field type of ACCESS database

Obtain the picture from an OLE field type of ACCESS database

I need to set a picture property of a commandbutton dinamically (at run-time) according to an OLE type field of ACCESS database.

commandbutton1.Picture = recordset !Olefieldname 'ERROR TYPE MISMATCH

plz help
ultra2 is offline   Reply With Quote
Old Jun 27th, 2005, 02:54 PM   #2
RhinoBull
PowerPoster
 
RhinoBull's Avatar
 
Join Date: Mar 04
Location: New Amsterdam
Posts: 21,118
RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)
Re: Obtain the picture from an OLE field type of ACCESS database

Search through my posts - I have two procedures posted: one to store files and one to read them back.
RhinoBull is offline   Reply With Quote
Old Jun 27th, 2005, 02:55 PM   #3
dglienna
Banned
 
dglienna's Avatar
 
Join Date: Jun 04
Location: Center of it all
Posts: 17,901
dglienna is a glorious beacon of light (400+)dglienna is a glorious beacon of light (400+)dglienna is a glorious beacon of light (400+)dglienna is a glorious beacon of light (400+)dglienna is a glorious beacon of light (400+)dglienna is a glorious beacon of light (400+)
Re: Obtain the picture from an OLE field type of ACCESS database

Try this. I'm not sure if you can load any type of picture onto a command button. Why don't you use a Picturebox, and use it's click event as a button?


VB Code:
  1. commandbutton1.Picture = LoadPicture(recordset !Olefieldname)
dglienna is offline   Reply With Quote
Old Jun 27th, 2005, 02:58 PM   #4
RobDog888
Super Moderator
 
RobDog888's Avatar
 
Join Date: Apr 01
Location: LA, Calif. Raiders #1 AKA:Gangsta Yoda™
Posts: 58,875
RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)
Re: Obtain the picture from an OLE field type of ACCESS database

Quote:
Originally Posted by dglienna
Try this. I'm not sure if you can load any type of picture onto a command button. Why don't you use a Picturebox, and use it's click event as a button?


VB Code:
  1. commandbutton1.Picture = LoadPicture(recordset !Olefieldname)
Sure you can. Just set the Style property to graphical and then load your image to its Picture property.
__________________
VB/Office Guru™ (AKA: Gangsta Yoda®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.

Microsoft MVP 2006, 2007, 2008, 2009, 2010
Office Development FAQ (VBA, VB 6, VB.NET, C#)
Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007
RobDog888 is offline   Reply With Quote
Old Jun 27th, 2005, 03:04 PM   #5
RhinoBull
PowerPoster
 
RhinoBull's Avatar
 
Join Date: Mar 04
Location: New Amsterdam
Posts: 21,118
RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)
Re: Obtain the picture from an OLE field type of ACCESS database

You have to extract file first, store it on the hard disk and then use LoadPicture() to actually load image into whatever control ...
RhinoBull is offline   Reply With Quote
Old Jun 28th, 2005, 04:26 AM   #6
ultra2
Lively Member
 
Join Date: Jun 05
Posts: 81
ultra2 is an unknown quantity at this point (<10)
Re: Obtain the picture from an OLE field type of ACCESS database

it doesnt work:
commandbutton1.Picture = LoadPicture(recordset !Olefieldname)

ok, i have to save the pic to hdd, but how can I do this?


plz, help, im very new in VB.
ultra2 is offline   Reply With Quote
Old Jun 28th, 2005, 08:16 AM   #7
RhinoBull
PowerPoster
 
RhinoBull's Avatar
 
Join Date: Mar 04
Location: New Amsterdam
Posts: 21,118
RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)
Re: Obtain the picture from an OLE field type of ACCESS database

Here is a "ready-to-go" logic to extract image from database and load it into the Image control or Picturebox (your choice - read my comments):
VB Code:
  1. Option Explicit
  2. Private Const MAX_PATH = 260
  3. Private Const BLOCK_SIZE = 10000
  4. Private Declare Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA" _
  5.     (ByVal lpszPath As String, ByVal lpPrefixString As String, _
  6.      ByVal wUnique As Long, ByVal lpTempFileName As String) As Long
  7. Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" _
  8.     (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
  9. Public Sub ExtractImage(adoConn As ADODB.Connection, _
  10.                         sPicId As String, imgTemp As Image)
  11. '=======================================================================================
  12. 'NOTES:
  13. '* this samples requires table ALL_PICTURES (could be any name) with at least 3 fields:
  14. '   - PICTURE_ID    (could be text or number)
  15. '   - ACTUAL_IMAGE  (OLE Object)
  16. '   - IMAGE_SIZE    (Number - Long)
  17. '
  18. '* adoConn must be valid and open connection to your database
  19. '* imgTemp can be define as Picturebox as well
  20. '* also, instead of sPicId you may pass entire sql statement
  21. '* logic is "adaptable" for any other database type including Oracle, SQL Server, ...
  22. '  however, field type will differ: in Oracle it would be "Long RAW" ...
  23. '* you may add one more field IMAGE_TYPE (text) so you know what type of file is stored
  24. '  so if it is some kind of image then you would use LoadImage() or if is not then
  25. '  you may need to simply open extracted file.
  26. '======================================================================================
  27. Dim adoRST As ADODB.Recordset, strSql$
  28. Dim bytes() As Byte
  29. Dim file_name As String
  30. Dim file_num As Integer
  31. Dim file_length As Long
  32. Dim num_blocks As Long
  33. Dim left_over As Long
  34. Dim block_num As Long
  35. Dim hgt As Single
  36. On Error GoTo ErrHandler
  37.     Screen.MousePointer = vbHourglass
  38.     DoEvents
  39.    
  40.     strSql = "SELECT * FROM ALL_PICTURES WHERE PICTURE_ID = '" & sPicId & "'"
  41.    
  42.     Set adoRST = New ADODB.Recordset
  43.     adoRST.Open strSql, adoConn
  44.    
  45.     If adoRST.EOF Then
  46.         Screen.MousePointer = vbDefault
  47.         Exit Sub
  48.     End If
  49.    
  50.     If IsNull(adoRST.Fields("ACTUAL_IMAGE")) Then
  51.         Screen.MousePointer = vbDefault
  52.         Exit Sub
  53.     End If
  54.    
  55.     ' Get a temporary file name.
  56.     file_name = TemporaryFileName()
  57.    
  58.     ' Open the file.
  59.     file_num = FreeFile
  60.     Open file_name For Binary As #file_num
  61.         ' Copy the data into the file.
  62.         file_length = adoRST.Fields("IMAGE_SIZE")
  63.        
  64.         num_blocks = file_length / BLOCK_SIZE
  65.         left_over = file_length Mod BLOCK_SIZE
  66.        
  67.         'get all chunks and write then to a temp file
  68.         For block_num = 1 To num_blocks
  69.             bytes() = adoRST.Fields("ACTUAL_IMAGE").GetChunk(BLOCK_SIZE)
  70.             Put #file_num, , bytes()
  71.         Next block_num
  72.         If left_over > 0 Then
  73.             bytes() = adoRST.Fields("ACTUAL_IMAGE").GetChunk(left_over)
  74.             Put #file_num, , bytes()
  75.         End If
  76.     Close #file_num
  77.    
  78.     'load image
  79.     '****************************************
  80.     imgTemp.Picture = LoadPicture(file_name)
  81.     '****************************************
  82.    
  83.     Screen.MousePointer = vbDefault
  84.     Exit Sub
  85. ErrHandler:
  86. '-----------
  87.     Debug.Print Err.Description
  88.     Err.Clear
  89.     Screen.MousePointer = vbDefault
  90.    
  91.     'Resume Next
  92.     Exit Sub
  93. End Sub
  94. Public Function TemporaryFileName() As String
  95. '==============================================
  96. Dim temp_path As String
  97. Dim temp_file As String
  98. Dim length As Long
  99.     ' Get the temporary file path.
  100.     temp_path = Space$(MAX_PATH)
  101.     length = GetTempPath(MAX_PATH, temp_path)
  102.     temp_path = Left$(temp_path, length)
  103.     ' Get the file name.
  104.     temp_file = Space$(MAX_PATH)
  105.     GetTempFileName temp_path, "per", 0, temp_file
  106.     TemporaryFileName = Left$(temp_file, InStr(temp_file, Chr$(0)) - 1)
  107. End Function
RhinoBull is offline   Reply With Quote
Old Jun 28th, 2005, 12:18 PM   #8
ultra2
Lively Member
 
Join Date: Jun 05
Posts: 81
ultra2 is an unknown quantity at this point (<10)
Re: Obtain the picture from an OLE field type of ACCESS database

ERROR: invalid picture

i just put the pic into the access as ole object..
ultra2 is offline   Reply With Quote
Old Jun 28th, 2005, 12:33 PM   #9
RhinoBull
PowerPoster
 
RhinoBull's Avatar
 
Join Date: Mar 04
Location: New Amsterdam
Posts: 21,118
RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)
Re: Obtain the picture from an OLE field type of ACCESS database

I have no clue how you do it so if you want then take a look at my replies in this thread .
RhinoBull is offline   Reply With Quote
Old Nov 25th, 2005, 02:56 AM   #10
doremon
New Member
 
Join Date: Nov 05
Posts: 1
doremon is an unknown quantity at this point (<10)
Re: Obtain the picture from an OLE field type of ACCESS database

hi, i wanted to use the ole pictures stored to be displayed in php. but all i get is gibberish after i convert the hex to string. is it my header wrong? my header is content-type : image/jpeg (this is done in separate file called test.php). then, another php content is <img src="test.php?id=123"> calling test.php

still no image.. please help :-(
doremon is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:01 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.