คือว่าอยากให้รูปที่แอดเข้าไปในระเบียงเดียวกัน สามารถเปิดได้ หลายรูปโดยเขียนโคตไว้แล้วพอคลิกที่ปุ่มจะขยายใหญ่ขึ้นมาแต่ ตอนนี้ได้แค่ 1 ระเบียงต่อ 1 รูปเองครับ ควรทำยังไงดี
โค๊ต
Option Compare Database
Public Function ifileDialog() As String
Dim Flie As Object
Set File = Application.FileDialog(3)
With File
.Title = "Select Picture"
.Filters.Add "Images", "*.gif; *.jpg; *.bmp, *.png, *.tif", 1
.Filters.Add "All Files", "*.*"
.FilterIndex = 1
.AllowMultiSelect = False
End With
If File.show Then
ifileDialog = File.SelectedItems.Item(1)
End If
End Function
Sub Add_Attachments(tName As String, fName As String, attName As String)
Dim db As DAO.Database, rs As DAO.Recordset, rsChild As DAO.Recordset2, iPath As String
iPath = ifileDialog
If iPath & "" <> "" Then
Set db = CurrentDb
Set rs = db.OpenRecordset(tName)
If Dir(iPath, vbNormal) <> "" Then
rs.AddNew
rs(fName) = Mid(iPath, InStrRev(iPath, "\") + 1)
Set rsChild = rs.Fields(attName).Value
rsChild.AddNew
rsChild.Fields("FileData").LoadFromFile (iPath)
rsChild.Update
rs.Update
End If
Set rsChild = Nothing
Set rs = Nothing
db.Close
Set db = Nothing
End If
End Sub
Sub Export_Attachments(tName As String, attName As String, pName As String)
Dim db As DAO.Database, rs As DAO.Recordset, rsChild As DAO.Recordset2, iPath As String
iPath = CurrentProject.Path
Set db = CurrentDb
Set rs = db.OpenRecordset(tName, dbOpenDynaset)
rs.FindFirst "[Name_Picture] = '" & pName & "'"
Set rsChild = rs.Fields(attName).Value
If Dir(iPath & "\" & rsChild.Fields("FileName"), vbNormal) = "" Then
rsChild.Fields("FileData").SaveToFile iPath
End If
Set rsChild = Nothing
Set rs = Nothing
db.Close
Set db = Nothing
End Sub
ที่ปุ่ม add และ open
Private Sub cmdADD_Click()
Add_Attachments "tb_picture", "Name_picture", "Images"
Me.Requery
End Sub
Private Sub Command4_Click()
Export_Attachments "tb_picture", "Images", Me.txtName_Picture
Dim iPath As String
iPath = CurrentProject.Path & "\" & Me.txtName_Picture
DoCmd.OpenForm "Form2"
Forms!Form2.SetFocus
Forms!Form2.Image0.Picture = iPath
End Sub
ขอบคุณครับ
เครดิตโค๊ต Access-Creator