473,326 Members | 2,175 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Populate lstBox dynamically on a report -

13
two questions: 1 - i am using this on my form to populate the lst box showing sub folders, works fine but i need to show only the information after txt in the lstBox and 2- i would like to use this code in creating the report in ms access but report won't accept add function because it is in print mode - is it possible to work around this? many thanks

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim Fso As Object       'to hold FSO
  3.     Dim fmain As Folder     'to hold reference to top level subfolders
  4.     Dim flevel1 As Folder   'to hold reference to 1st level subfolders
  5.     Dim flevel2 As Folder   'to hold reference to 2nd level subfolders
  6.     Dim aFile As File       'to hold reference to Files
  7.     Dim lst As ListBox
  8. Dim txt As TextBox
  9. Dim strFileName As String
  10. Dim strPath As String
  11.  
  12.  
  13. Set lst = Me![lstFilesInSubDirectory]
  14. Set txt = Me![txtFilePath]
  15.  
  16.  
  17.  
  18.  
  19.     Set Fso = CreateObject("Scripting.FileSystemObject")
  20.     'Assign the folder to loop
  21.     Set fmain = Fso.GetFolder(txt)   'Pass your folder path here
  22.  
  23.     'this code loops through the folders,subfolders and files
  24.     'this works only upto 2 levels of subfolders
  25.       For Each flevel1 In fmain.SubFolders
  26.           For Each aFile In flevel1.files
  27.             lst.AddItem aFile.Path
  28.  
  29.  
  30.  
  31.  
  32.           Next
  33.          'loops second level subfolders
  34.           If flevel1.SubFolders.Count > 0 Then
  35.               For Each flevel2 In flevel1.SubFolders
  36.                 For Each aFile In flevel2.files
  37.                   lst.AddItem aFile.Path
  38.                 Next
  39.               Next
  40.           End If
  41.       Next
  42.  
  43.     Set fmain = Nothing
  44.     Set flevel1 = Nothing
  45.     Set flevel2 = Nothing
  46.     Set aFile = Nothing
  47.     Set Fso = Nothing
  48.  
  49.  
  50. End Sub
  51.  
May 6 '11 #1
2 1821
ADezii
8,834 Expert 8TB
I am not sure if I understand your request completely, but if you are asking to use the existing Code but only for the Folder specified in the Text Box txt, and not any Sub-Folders:
Expand|Select|Wrap|Line Numbers
  1. Dim Fso As Object       'to hold FSO
  2. Dim fmain As Folder     'to hold reference to top level subfolders
  3. Dim flevel1 As Folder   'to hold reference to 1st level subfolders
  4. Dim aFile As File       'to hold reference to Files
  5. Dim lst As ListBox
  6. Dim txt As TextBox
  7.  
  8. Set lst = Me![lstFilesInSubDirectory]
  9. Set txt = Me![txtFilePath]
  10.  
  11. Set Fso = CreateObject("Scripting.FileSystemObject")
  12.   Set fmain = Fso.GetFolder(txt)
  13.     For Each aFile In fmain.Files
  14.       lst.AddItem aFile.Path
  15.     Next
  16.  
  17. Set fmain = Nothing
  18. Set flevel1 = Nothing
  19. Set aFile = Nothing
  20. Set Fso = Nothing
May 6 '11 #2
katia
13
Hi ADezii;
Q1- the code works on my form with the exception that sometimes i get an error because the results from all the sub folder search is too big for the list box (it returns the complete file path for subfolders) - so I would like to display only the text from the return search that comes after the filepath (txt), into the listbox -

Q2 - the code works on the form just fine, but does not work on a report - does not get the information dynamically to display as part of the report. not sure i can even do this? it seems reports go into print mode right away or something - so won't let the code run because print is running.... i think this is the problem anyway.
May 13 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: George Hester | last post by:
What's this? IE has a simple way using an ActiveX object so that I can load a text file into the <OPTION>s like a database. It is called Tabular Control. But I doubt this is going to work with...
0
by: amber | last post by:
Hello, I needed to add a subreport to an existing report I've created in VB.NET/Crystal Reports. Pasted below is the code I use to open my existing report. This works fine. How do I pass a 2nd...
1
by: Swadh | last post by:
Hi, I need urgent help on Windows Form datagrid. I have to Display a datagrid that has a textbox column and another one combo box column. I have two tables in my Access database as: Table 1:...
0
by: Pierre | last post by:
Hi, Can anyone tell me how I can populate a Crystal Report, using a DataTable in C#? Regards, Pierre
0
by: dcstech | last post by:
Does anyone have an example on how to populate a crystal report with data from a datagrid and print it. Thanks DCSTech
1
by: Rohit111111 | last post by:
Hello How can i use the table control ,meanse i have to make rows and coloumn dynamically with proper pagination
0
by: lianaent | last post by:
Hi All, I'm brand new to asp.net 2.0, and have a simple task of just creating a quick and dirty data entry form with SQL Server 2005 on the back end. I added a gridview to my form, and I can...
0
Lokean
by: Lokean | last post by:
If so, could someone point me in the right direction, I am a newbie to crystal
4
parshupooja
by: parshupooja | last post by:
Hey All, I have a dropdown on my page. I want to populate dropdown dynamically via code. Here is a scenario. for each year it should populate items automatically. such as most current item it...
3
by: vljones | last post by:
I have a report with sub reports. The sub reports are query based. The queries perform a Count. Where no data exists in the table, no results are provided. Is there a way to populate the sub...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
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...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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....
0
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
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.