Salve a tutti. Ho letto molti dei vostri post per arrivare a creare un pulsante sulla mia maschera che provveda a selezionare un file da caricare, tramite collegamento ipertestuale, all'interno di un DB.
Sembrava tutto perfetto e invece non riesco a risolvere questo problema: vi posto il codice che ho usato fino ad ora:
Private Sub Comando40_Click()
getFileName
End Sub
Private Sub Form_Current()
' Display the picture for the current employee record if the image
' exists. If the file name no longer exists or the file name was blank
' for the current employee, set the errormsg label caption to the
' appropriate message.
Dim res As Boolean
Dim fName As String
Path = CurrentProject.Path
On Error Resume Next
errormsg.Visible = False
If Not IsNull(Me!Logo_Tessera) Then
res = IsRelative(Me!Logo_Tessera)
fName = Me![ImagePath]
If (res = True) Then
fName = Path & "\" & fName
End If
Me![ImageFrame].Picture = fName
showImageFrame
Me.PaintPalette = Me![ImageFrame].ObjectPalette
If (Me![ImageFrame].Picture <> fName) Then
hideImageFrame
errormsg.Caption = "Foto non trovato"
errormsg.Visible = True
End If
Else
hideImageFrame
errormsg.Caption = "Clicca Aggiungi/Modifica per aggiungere la foto"
errormsg.Visible = True
End If
End Sub
Sub getFileName()
' Displays the Office File Open dialog to choose a file name
' for the current employee record. If the user selects a file
' display it in the image control.
Dim fileName As String
Dim result As Integer
Const msoFileDialogFilePicker = 1
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "Selezionare il file da caricare"
.Filters.Add "All Files", "*.*"
.Filters.Add "JPEGs", "*.jpg"
.Filters.Add "Docs", "*.doc"
.Filters.Add "Xlss", "*.xls"
.Filters.Add "pdfs", "*.pdf"
.Filters.Add "Bitmaps", "*.bmp"
.FilterIndex = 3
.AllowMultiSelect = False
'.InitialFileName = CurrentProject.Path
.InitialFileName = vp_path
result = .Show
If (result <> 0) Then
fileName = Trim(.SelectedItems.Item(1))
Me![ImagePath].Visible = True
Me![ImagePath].SetFocus
Me![ImagePath].Text = fileName
Me![Comando40].SetFocus
Me![ImagePath].Visible = False
End If
End With
End Sub
Sub showErrorMessage()
' Display the errormsg label if the image file is not available.
If Not IsNull(Me!Logo_Tessera) Then
errormsg.Visible = False
Else
errormsg.Visible = True
End If
End Sub
Function IsRelative(fName As String) As Boolean
' Return false if the file name contains a drive or UNC path
IsRelative = (InStr(1, fName, ":") = 0) And (InStr(1, fName, "\\") = 0)
End Function
Sub hideImageFrame()
' Hide the image control
Me![ImageFrame].Visible = False
End Sub
Sub showImageFrame()
' Display the image control
Me![ImageFrame].Visible = True
End Sub
Private Sub ImagePath_AfterUpdate()
' After selecting an image for the employee, display it.
On Error Resume Next
showErrorMessage
showImageFrame
If (IsRelative(Me!ImagePath) = True) Then
Me![ImageFrame].Picture = Path & Me![ImagePath]
Else
Me![ImageFrame].Picture = Me![ImagePath]
End If
End Sub
..in sostanza, nella SUB GET FILE NAME quando arrivo all'istruzione ME![IMAGEPATH].VISIBLE = TRUE mi da errore. Sono un novizio, però non riesco proprio a capire perché lo stesso codice fatto girare su un altro DB funziona, riadattato al mio DB no! Vi prego aiutatemi....se potete. Grazie mille!