Currently I only get the file path. Is there way to retrieve the file name or do I have to just use the split function. - Dim fDialog As Office.FileDialog
-
-
Dim varFile As Variant
-
-
'Clear listbox contents.
-
'Me.FileList.RowSource = ""
-
-
'Set up the File Dialog.
-
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 or more files"
-
-
'Clear out the current filters, and add our own.
-
.Filters.Clear
-
.Filters.Add "Access Databases", "*.MDB; *.ACCDB"
-
.Filters.Add "Access Projects", "*.ADP"
-
.Filters.Add "All Files", "*.*"
-
-
'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
-
'Loop through each file selected and add it to the list box.
-
For Each varFile In .SelectedItems
-
If IsNull(Me.addAttachmenttbox) Then
-
Me.addAttachmenttbox = varFile
-
Else
-
Me.addAttachmenttbox = Me.addAttachmenttbox & ";" & varFile
-
End If
-
Next
-
Else
-
MsgBox "You clicked Cancel in the file dialog box."
-
End If
-
End With
-
7 2465
I posted only the relevant code, Lines 3 and 27 will do the trick: - Dim fDialog As Office.FileDialog
-
Dim varFile As Variant
-
Dim strFileName As String
-
-
'Set up the File Dialog.
-
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 or more files"
-
-
'Clear out the current filters, and add our own.
-
.filters.Clear
-
.filters.Add "Access Databases", "*.MDB; *.ACCDB"
-
.filters.Add "Access Projects", "*.ADP"
-
.filters.Add "All Files", "*.*"
-
-
'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
-
'Loop through each file selected and add it to the list box.
-
For Each varFile In .SelectedItems
-
strFileName = Mid$(varFile, InStrRev(varFile, "\") + 1)
-
Debug.Print strFileName 'Testamundo!
-
Next
-
Else
-
MsgBox "You clicked Cancel in the file dialog box."
-
End If
-
End With
Thank you so much Adezii. I had used the split function and passed into an array but your way is much simpler.
I don't know if i have to open another question. Talking about the same File Dialog property, once a user selects multiple files I have added the file names to a list box (value list). I would like to set something up where the user can select multiple items to be deleted from the list box. Currently whith my code it only deletes one item instead of the selected items. The multiselect property is set to extended. See below I tried two ways. - Public Function removeAttachements(ctlList As ListBox)
-
-
iCount = 0
-
-
-
If ctlList.ItemsSelected.Count <> 0 Then
-
For i = ctlList.ListCount - 1 To 0 Step -1
-
-
If ctlList.Selected(i) Then
-
MsgBox i
-
ctlList.RemoveItem (i)
-
-
End If
-
Next i
-
Else
-
MsgBox "Nothing was selected from the list", vbInformation
-
Exit Function 'Nothing was selected
-
End If
-
-
End Function
or - Public Function removeAttachements(ctlList As ListBox)
-
Dim oItem As Variant
-
Dim sTemp As String
-
Dim iCount As Integer
-
-
iCount = 0
-
oItem = varTemp
-
-
If ctlList.ItemsSelected.Count <> 0 Then
-
For Each oItem In ctlList.ItemsSelected
-
ctlList.RemoveItem Index:=oItem
-
Next oItem
-
Else
-
MsgBox "Nothing was selected from the list", vbInformation
-
Exit Function 'Nothing was selected
-
End If
-
-
End Function
Both codes are only removing one item. Is there something I am doing wrong
Dynamically removing Multiple Items from a List Box at Runtime can be tricky because of the Re-indexing of the contents. If the RowSourceType of the List Box is Value List, why not simply rebuild the Row Source of the List Box, eliminating those Items that are currently selected? - Dim lst As ListBox
-
Dim i As Integer
-
Dim strBuild As String
-
-
Set lst = Me![ctlList]
-
-
With lst
-
If .ItemsSelected.Count <> 0 Then
-
For i = 0 To .ListCount - 1
-
If .Selected(i) = True Then
-
'do nothing, don't want it included in strBuild
-
Else
-
strBuild = strBuild & .ItemData(i) & ";"
-
End If
-
Next i
-
Else
-
MsgBox "Nothing was selected from the list", vbInformation
-
Exit Sub
-
End If
-
End With
-
-
Me![ctlList].RowSource = Left$(strBuild, Len(strBuild) - 1)
Hi Adezii,
My current list box has multiple columns. How would i be able to make this work.
Thank you,
You're really gonna make me work on this one, aren't you? (LOL). The comparable logic for a 3-Column List Box is: - Dim lst As ListBox
-
Dim i As Integer
-
Dim strBuild As String
-
-
Set lst = Me![ctlList]
-
-
With lst
-
If .ItemsSelected.Count <> 0 Then
-
For i = 0 To .ListCount - 1
-
If .Selected(i) = True Then
-
Else
-
strBuild = strBuild & .Column(0, i) & ";" & .Column(1, i) & _
-
";" & .Column(2, i) & ";"
-
End If
-
Next i
-
Else
-
MsgBox "Nothing was selected from the list", vbInformation
-
Exit Sub
-
End If
-
End With
-
-
Me![ctlList].RowSource = Left$(strBuild, Len(strBuild) - 1)
P.S. - Make the necessary adjustments for a Column Count <> 3
Hi Adezii
What can I say but just Damn you're good!
I had tried this - strBuild = strBuild & lst.Column(1, i) & ";" & lst.Column(2, i)
and I was getting an error looking at your code I see what I did wrong.
I wish there was a way I can thank you, you have saved me some time.
Time and time again you always come through.
Thank you very much. Untill next time (LOL), and don't worry you can sleep easy tonight. No more questions from me (LOL).
Thank you.
The pleasure is all mine, take care.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jim Witte |
last post by:
Hi,
How do I set a file input element? If it's a text input, I can set the
value property. But this doesn't work with file inputs.
And no, I can't change it - I'm writing a script to...
|
by: tkailler |
last post by:
Hello,
I've created a dialog by creating a class in which Instead of calling wx.Dialog.__init__ I precreate the dialog and then I create the GUI dialog using the Create method.
When I create...
|
by: MLH |
last post by:
I was running the following code while logged
in as a user belonging only to the Users group.
Set usrNew = .CreateUser(Me!UserID) 'The user ID is in a
control on the form
usrNew.PID =...
|
by: marco.nl |
last post by:
it fails to retrieve newly intruduced data by the user.
i tried this ...
AfxGetApp()->WriteProfileString("Settings", "email", EDIT1);
UpdateData(FALSE);
and this.....
|
by: simon |
last post by:
I created web application on file system, which is default by Visual studio
20005 beta2.
This gives me some strange port numbers.
How can I change, that my application will work on IIS?
I...
|
by: tigrrgrr42 |
last post by:
I am working(vb.net03and05) with word documents stored in a sql db and I am
currently bringing them from a byte array into a temp file to pop into word
and make word do its thing as a com object. ...
|
by: thjwong |
last post by:
I'm using WinXP with Microsoft Visual C++ .NET
69462-006-3405781-18776, Microsoft Development Environment 2003 Version
7.1.3088, Microsoft .NET Framework 1.1 Version 1.1.4322 SP1
Most developers...
|
by: tomromanul |
last post by:
Hi all,
I built a Windows Froms user control and I use it in IE 6+. It
functions properly (it displays properly in IE and executes code, such
as displaying a message box), except that in the web...
|
by: Peter Duniho |
last post by:
I searched using Google, on the web and in the newsgroups, and found nothing
on this topic. Hopefully that means I just don't understand what I'm
supposed to be doing here. :)
The problem:
...
|
by: lifeisgreat20009 |
last post by:
I am a newbie to Struts and JSP...I have been working on the code below for 5 hours now..I googled a lot but couldn't get much help so finally I am here.. Hoping of getting my problem solved. Please...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |