1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| 'Insèrer une image dans la base de donnée depuis l'ordinateur "Ilmage1"
Function insert_picture_to_database()
On Error Resume Next
If TextBox1 <> "" Then
Dim imgSourcePath As String
Dim imgDestination As String
Dim free_image As String
Dim GetImagePath As String
Dim strFolder As String
' Utilisez la boîte de dialogue de recherche de fichier
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Add "Images", "*.gif;*.jpg;*.jpeg;*.png;*.GIF;*.JPG;*.JPEG;*.PNG"
If .Show <> 0 Then
GetImagePath = .SelectedItems(1)
End If
End With
' Assurez-vous que l'utilisateur a sélectionné un fichier
If GetImagePath <> "" Then
' Obtenir le chemin complet du fichier
imgSourcePath = GetFullPath(GetImagePath)
strFolder = ThisWorkbook.Path & Application.PathSeparator & "Images"
If Dir(strFolder, vbDirectory) = "" Then
MkDir strFolder
End If
imgDestination = ThisWorkbook.Path & "\Images\" & UserForm1.TextBox1 & "." & Split(imgSourcePath, ".")(UBound(Split(imgSourcePath, ".")))
FileCopy imgSourcePath, imgDestination
UserForm1.Image1.PictureSizeMode = fmPictureSizeModeZoom
UserForm1.Image1.Picture = LoadPicture(imgDestination)
free_image = imgSourcePath
Me.TextBox20 = free_image
End If
Else
MsgBox "Entrez un nom!"
End If
End Function |
Partager