Dustin Stanley
asked on
MS Access Filedialog Multiselect to Subform Add New Record Help!
I have a Filedialog that works great for single select but I need to be able to use multiselect. I click a add image button and on_click it calls to a Public Function AddLocalImagePath. That function then runs a series of commands to place the filepath name into a control on the subform.
I have been at this for hours and hours! What I have is below. Thank you!
AddLocalImagePath function in the subform sbfrmProductImages:
FileDialog in a module:
I have been at this for hours and hours! What I have is below. Thank you!
AddLocalImagePath function in the subform sbfrmProductImages:
Public Function AddLocalImagePath() As Variant
Dim strImagePath As Variant
strImagePath = ImagePathMulti
If Me.NewRecord Then
DoCmd.GoToControl "sbfrmProductImages"
Me!ProductImageFileNm.Value = Dir$(strImagePath)
Else
DoCmd.GoToControl "sbfrmProductImages"
DoCmd.GoToRecord , , acNewRec
Me!ProductImageFileNm.Value = Dir$(strImagePath)
End If
Call ImageRequery
End Function
FileDialog in a module:
Public Function ImagePathMulti() As String
Dim fd As FileDialog
Dim FileChosen As Integer
Dim FileName As String
Dim I As Integer
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'use the standard title and filters, but change the
'initial folder
fd.InitialFileName = "\\1-PC\Database\Images\"
fd.InitialView = msoFileDialogViewList
'allow multiple file selection
fd.AllowMultiSelect = True
FileChosen = fd.Show
If FileChosen <> -1 Then
Exit Function
Else
'open each of the files chosen
For I = 1 To fd.SelectedItems.Count
ImagePathMulti = fd.SelectedItems(I)
Next I
End If
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You must set rst to a recordset (or recordsetclone) and you can't use ImagePathMulti as variable name as it is the name of the function.
/gustav
/gustav
ASKER
I changed imagePathMulti to a string but I am very confused on the setting the recordset. I dimmed rst as recordset. But if I set it to a table isn't this going to just add the records directly to the table instead of my subform? I need it to know which Mainform SkuID (Master/Child Link) the ProductImages go to. Sorry I'm just not getting it. Thanks for your help!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for your help! Seriously thank you! I have gotten it to do multi select and insert file names only into the correct subform position correctly BUT it leaves SkuID control field blank in the Subform and it has to match the Main Forms SkuID control field in order for the image names to be synced with the right product. Again thank you!
In My main form frmSKUsEntry:
in my subform sbfrmProductImages:
In My main form frmSKUsEntry:
Private Sub btnAddImage_Click()
Forms!frmSkusEntry!sbfrmProductImages.Form.AddLocalImagePath
End Sub
in my subform sbfrmProductImages:
Public Function AddLocalImagePath() As Variant
Dim strImagePath As String
strImagePath = ImagePathMulti
If Me.NewRecord Then
DoCmd.GoToControl "sbfrmProductImages"
Else
DoCmd.GoToControl "sbfrmProductImages"
DoCmd.GoToRecord , , acNewRec
End If
Call ImageRequery
End Function
Public Function ImagePathMulti() As String
Dim fd As FileDialog
Dim FileChosen As Integer
Dim FileName As String
Dim I As Integer
Dim rst As Recordset
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'use the standard title and filters, but change the
'initial folder
fd.InitialFileName = "\\SURPIUS1-PC\OneDrive\SurpiusDatabase\Images"
fd.InitialView = msoFileDialogViewList
'allow multiple file selection
fd.AllowMultiSelect = True
FileChosen = fd.Show
If FileChosen <> -1 Then
Exit Function
Else
Set rst = Me.RecordsetClone
' Open each of the files chosen.
For I = 1 To fd.SelectedItems.Count
ImagePathMulti = fd.SelectedItems(I)
If ImagePathMulti <> "" Then
' Insert record.
rst.AddNew
rst!ProductImageFileNm.Value = Dir$(ImagePathMulti)
rst.Update
End If
Next
End If
End Function
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
But can't you just set that field too?Yes if i had that knowledge and now I do. Thank you Gustav! JUST BRILLIANT!!!!!!!!!!!!!!!!!
ASKER
Thank you!
You are welcome!
/gustav
/gustav
ASKER
Open in new window