Embedded OLE Pictures
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 318   3
URL.หัวข้อ / URL
Embedded OLE Pictures

มีคนถามไว้ที่ 
http://www.utteraccess.com/forums/showflat.php?Cat=&Board=AxxessXP&Number=110368&page=0&view=collapsed&sb=5&o=7&fpart=1&vc=1&PHPSESSID= 
 
ดังนี้ 
My question has been asked before but it still remains unanswered so I  
apologize in advance. 
 
I have a table that has among others a field named EmployeeNo (Long Int) and  
a field named Picture (OLE Object). All of the pictures have been embedded ,  
rather than linked. 
 
My question: Is it possible to export the picture as a .bmp, .jpg, (any type of  
image file will do) using the EmployeeNo as the FileName? 
 
Thanks in advance.  
Wendell  
 
เขาต้องการที่จะ export รูปที่เขาใส่เข้าในในแต่ละข้อมูล ซึ่งเก็บแบบ Embedded (คือฝั่งไว้เลย โดยจะไม่มีการเก็บชื่อไฟล์และห้องของภาพนั้นไว้) ถามว่าเป็นไปได้หรือไม่ที่จะนำไปเขียนเป็นภาพ แล้วบันทึกเป็นนามสกุลอะไรก็ได้ โดยตั้งชื่อให้ตรงกับ EmployeeNo 
 
ผมเข้าไปอ่านครั้งหนึ่งแล้ว ลองมาทำตามคำแนะนำของไมโครซอฟต์ดู ก็ไม่สามารถทำได้ ที่เห็นมีแต่แนะนำให้ copy แล้วไป paste ลงใน Paint เอาเองด้วยมือ ดูที่ http://support.microsoft.com/default.aspx?scid=kb;en-us;q166843 
 
ผมจึงหยุดไป เมื่อกี้นี้ผมเข้าไปดูอีกเห็นมีคนเข้ามาตอบ แต่เป็นเจ้าของกระทู้เอง พูดทำนองคล้ายกับว่า ไม่เห็นมีใครเข้ามาตอบเลย ทำได้หรือไม่ได้ให้บอกมา แกจะได้ตัดสินใจถูกว่าควรจะทำโปรเจ็คท์นี้ต่อไปหรือไม่ 
 
ผมเลยได้เสนอความคิดให้เขาไปว่า 
เราสามารถที่จะใช้ SendKeys กับโปรแกรมกราฟฝิ่คได้มั๊ย ถ้าได้ก็น่าจะทำได้ โดยการคลิก 2 ที่รูปภาพ แล้วส่งค่า EmployeeNo ไปเป็นชื่อไฟล์ให้เองโดยอัตโนมัติ 
 
จากนั้นผมก็มาลองทำกับไฟล์ตัวอย่างที่ Access ให้มาชื่อ Northwind.mdb แล้วก็ได้ใช้ได้ครับ ดังนี้ 
 
Private Sub cmdSaveAsNewFile_Click() 
' Set focus to the OLE Object 
Me.Photo.SetFocus 
' Copy the picture 
SendKeys "%EC", True 
' Open MSPaint.ext and show it on the top 
' You have to set Attributes (size of the canvase in Image menu>Attributes...) 
' to 192 width and 223 height in pixel before running this process. 
' The Attributes will be set as a defualt canvas. 
Call Shell("mspaint.exe", vbMaximizedFocus) 
' Paste the picture to MSPaint 
SendKeys "%EP", True 
' Save the new file with BMP extension 
SendKeys "%FS" & "c:\" & Me.EmployeeID & ".bmp" & "~" 
' Close MSPaint and return to Access 
SendKeys "%FX", True 
End Sub 
 
ลองอ่านคำอธิบายใน comment ที่ผมใส่ไว้นะครับ *** Edited by Supap Chaiya *** 21/10/2546 15:45:09

3 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R00654
เขาทำตามโค้ดผมไม่ได้ เลยได้ลองทำตัวอย่างให้เขาดู และนี่คือตัวอย่างครับ http://www.utteraccess.com/forums/uploads/110889-CopyEmbeddedPict.zip
2 @R00762
มีคนมาโพสต์ต่อจากผม และได้แนะนำการเขียนโค้ดเพื่อใส่ภาพเข้าไปในตารางและการดึงภาพไปเขียนเป็นไฟล์ใหม่ โดยเขาให้ไปศึกษาจากโค้ดของ Microsoft เองที่ http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q103257& ลองไปศึกษาโค้ดดูนะครับ
3 @R00973
และที่ http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=32967 ก็มีการยกตัวอย่างให้นำมาศึกษากันได้อีกแบบ
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0439s