ciao Nicola,
immaginavo che l'obiettivo fosse quello descritto in questo tuo ultimo post.
si la listbox deve essere non associata per come l'ho pensata io.
allora intanto prova così.
Estrapola tutto il fileDialog in una function allì'interno del modulo di classe della maschera e copia quanto sotto nel command button che usi per allegare il file.
se il record è null ci sono dei controlli aggiuntivi per evitare l'errore che ci manifesta, non ho verificato bene la modalità di generazione.
Modifica ovviamente il campo allegato nella tabella come allegato....( !!!! ) è impostato come testo nel demo che hai pubblicato.
ho testato il tutto e gli allegati vengono inseriti nella tabella.
ciao, Sandro.
Private Function ffFileDialog() As Variant
Dim fDialog As Office.FileDialog
Dim varFile As Variant
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
' Allow user to make multiple selections in dialog box
.AllowMultiSelect = True
' Set the title of the dialog box.
.Title = "Please select one file"
' Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "All Files", "*.*"
.Filters.Add "Access Databases", "*.MDB"
.Filters.Add "Access Projects", "*.ADP"
.Filters.Add "Access Projects", "*.ACCDB"
.InitialFileName = Application.CurrentProject.Path & ""
' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then
ffFileDialog = .SelectedItems(1)
Else
End If
End With
End Function
poi copia questo nel comman button allegato:
Dim rst As dao.Recordset2
Dim rstAtt As dao.Recordset2
Dim fld As dao.Field2
Dim dbs As dao.Database
Dim strPath As String
Dim strPk As String
strPath = Nz(ffFileDialog())
If strPath = "" Then Exit Sub
Set dbs = DBEngine(0)(0)
Set rst = dbs.OpenRecordset("SELECT * FROM tblAccettazione WHERE matricola = '" & Me.Matricola & "'")
Set fld = rst!Allegato
Set rstAtt = fld.Value
rst.Edit
rstAtt.AddNew
rstAtt!FileData.LoadFromFile strPath
rstAtt.Update
rst.Update
strPk = Me.Matricola
Me.Requery
Me.RecordsetClone.FindFirst "[matricola] = '" & strPk & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark
' This requires a reference to the Microsoft Office 11.0 Object Library.
Set dbs = Nothing
Set rstAtt = Nothing
Set rst = Nothing
Set fld = Nothing