473,401 Members | 2,125 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,401 software developers and data experts.

Converting a foundfile string to a text box string

Hi, i have a form which displays records containing a filepath field. When a button is pressed all the filepath fields are checked and the form is refiltered to display only those with invalid file paths. Upon pressing a second button each file is searched for on the computer. Currently all the matches are just written to a list box. What i want to happen is if there is only one match then that match's file path is written to the record's file path field. I have tried to write code for this but does not work:

Expand|Select|Wrap|Line Numbers
  1.                 If fs.Execute() = 1 Then
  2.  
  3.                     URL = fs.FoundFiles
  4.  
  5.                 End If
  6.  
When this segment of code is run i get an error message: "The value you entered isn't valid for this field". I am guessing that this is because the text stored in the .foundfiles property is of the wrong type. Is there a way of outputting the file path found by the search to the url textbox either from the foundfiles property itself or the list box?
Jan 18 '08 #1
6 3287
JKing
1,206 Expert 1GB
Hi there,

The FoundFiles property returns an object. It's basically an array of filepaths. Therefore it is indexed and if you want to get only a single filepath you will need to specify an index.

Expand|Select|Wrap|Line Numbers
  1. fs.FoundFiles(index)
  2.  
Where index is any number from 0 to FoundFiles.Count - 1.

There are several ways you could do a check to see if only 1 file is returned. The count property would be great for this.

If you would like to see a more detailed example or more information about the FoundFiles property have a look in the help files.
Jan 18 '08 #2
Cheers JKing, that part of the problem is now fixed. As a follow-problem I said if there were multiple files found I wanted the file paths added to a list box. I kind of managed to do this but have a problem. I set up the form so each record has a list-box. The list box isn't attached to a field or anything its just there for when there are multiple search results. The problem I'm having is that if for example a search of five files produced two matches of each file, I get all 10 results displayed in each list box on each record. I want it so only the multiple matches of each file are displayed in it's respective record, not all the matches of all the files. Is this happening because the list box isnt attached to a proper field?

Hi there,

The FoundFiles property returns an object. It's basically an array of filepaths. Therefore it is indexed and if you want to get only a single filepath you will need to specify an index.

Expand|Select|Wrap|Line Numbers
  1. fs.FoundFiles(index)
  2.  
Where index is any number from 0 to FoundFiles.Count - 1.

There are several ways you could do a check to see if only 1 file is returned. The count property would be great for this.

If you would like to see a more detailed example or more information about the FoundFiles property have a look in the help files.
Jan 19 '08 #3
JKing
1,206 Expert 1GB
If I'm understanding you correctly you want the listbox to only display the returned values of the current search and not accumulate the results from previous searches.

If this is the case you need to clear the data out of the listbox each to you add new data.

If you post your code that you are using to manipulate the listbox I can give you some more detail as how to go about doing this.
Jan 22 '08 #4
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. Do Until Form.CurrentRecord = CountDisplay
  4.  
  5.             'slashfrontpos = InStrRev(URL, "\")
  6.             'URLLength = Len(URL)
  7.             'slashbackpos = URLLength - slashfrontpos
  8.             'Extract = Right(URL, slashbackpos)
  9.  
  10.             'pointfrontpos = InStrRev(URL, ".")
  11.             'URLLength = Len(URL)
  12.             'pointbackpos = URLLength - pointfrontpos
  13.             'Extension = "*." + Right(URL, pointbackpos)
  14.  
  15.             If Drive = "" Then
  16.                 Drive = Left(URL, 3)
  17.             End If
  18.  
  19.             fs.NewSearch
  20.  
  21.             With fs
  22.  
  23.                 .LookIn = "C:;D:"
  24.                 .SearchSubFolders = True
  25.                 .filename = Extract
  26.                 .MatchTextExactly = True
  27.                 .Filetype = msoFileTypeAllFiles
  28.  
  29.             End With
  30.  
  31.             If fs.Execute > 0 Then
  32.  
  33.                 'If only 1 match was found, amend record, if >1 add file paths to list box
  34.                 If fs.FoundFiles.Count = 1 Then
  35.  
  36.                     URL = fs.FoundFiles(1)
  37.                     ValidPath = -1
  38.                     corrected = corrected + 1
  39.  
  40.                 Else
  41.  
  42.                     For i = 1 To fs.FoundFiles.Count
  43.                     SearchResults.AddItem fs.FoundFiles(i)
  44.                     Next i
  45.  
  46.                     multiple = multiple + 1
  47.  
  48.                 End If
  49.  
  50.             Else
  51.  
  52.                 none = none + 1
  53.  
  54.             End If
  55.  
  56.             'If the current record number = total number of records with invalid file paths
  57.             'exit sub, if not then go to next record
  58.             If Form.CurrentRecord = TotalInvalid Then
  59.  
  60.                 If corrected > 0 Then
  61.  
  62.                     If corrected = 1 Then
  63.                         MsgBox corrected & " music file had it's file path corrected automatically."
  64.                     Else
  65.                         MsgBox corrected & " music files had their file paths corrected automatically."
  66.                     End If
  67.  
  68.                 End If
  69.  
  70.                 If multiple > 0 Then
  71.  
  72.                     SearchResults.Enabled = True
  73.  
  74.                     If multiple = 1 Then
  75.                         MsgBox multiple & " music file had more than one match in the search."
  76.                     Else
  77.                         MsgBox multiple & " music files had more than one match in the search."
  78.                     End If
  79.  
  80.                     Overwrite.Enabled = True
  81.  
  82.                 End If
  83.  
  84.                 If none > 0 Then
  85.  
  86.                     If none = 1 Then
  87.                         MsgBox none & " music file had no matches in the search."
  88.                     Else
  89.                         MsgBox none & " music files had no matches in the search."
  90.                     End If
  91.  
  92.                 End If
  93.  
  94.                 Exit Do
  95.  
  96.             Else
  97.  
  98.                 DoCmd.GoToRecord , , acNext
  99.  
  100.             End If
  101.  
  102.         Loop
  103.  
  104.  
Theres quite a lot of unrelevent stuff in the loop so i commented it out for this post. The list box is called searchresults. I have tried writing code to do it but i end up with the last records search results in all the search result boxes.

If I'm understanding you correctly you want the listbox to only display the returned values of the current search and not accumulate the results from previous searches.

If this is the case you need to clear the data out of the listbox each to you add new data.

If you post your code that you are using to manipulate the listbox I can give you some more detail as how to go about doing this.
Jan 27 '08 #5
JKing
1,206 Expert 1GB
Your problem is that you are constantly adding to the listbox but never removing the existing items.

There are 3 ways you can fix this.

Method 1
Expand|Select|Wrap|Line Numbers
  1. Else
  2.                     'Set value list of the list box to an empty string to clear all values
  3.                     Me.SearchResults.RowSource = ""
  4.  
  5.                     For i = 1 To fs.FoundFiles.Count
  6.  
  7.                     SearchResults.AddItem fs.FoundFiles(i)
  8.  
  9.                     Next i
  10.  
  11.                     multiple = multiple + 1
  12. End If
  13.  
Method 2
Expand|Select|Wrap|Line Numbers
  1. Else
  2.                     'Loop through the listbox and remove existing items
  3.                     Do While Me.List1.ListCount > 0
  4.                             Me.List1.RemoveItem (0)
  5.                     Loop
  6.  
  7.                     For i = 1 To fs.FoundFiles.Count
  8.  
  9.                     SearchResults.AddItem fs.FoundFiles(i)
  10.  
  11.                     Next i
  12.  
  13.                     multiple = multiple + 1
  14. End If
  15.  
Method 3
Expand|Select|Wrap|Line Numbers
  1. 'Declare a string
  2. Dim strRowSource As String
  3.  
  4. strRowSource = ""
  5. Else
  6.                     'Build String
  7.                     For i = 1 To fs.FoundFiles.Count
  8.  
  9.                     strRowSource = strRowSource & fs.FoundFiles(i) & ";"
  10.  
  11.                     Next i
  12.  
  13.                     'Set ListBox rowsource to string
  14.                     SearchResults.RowSource = strRowSource
  15.  
  16.                     multiple = multiple + 1
  17. End If
  18.  
Jan 30 '08 #6
I have tried all three of the ways you suggested, but the same problem keeps occuring. This is where only the last search results are displayed in each list box. I think im putting the code in the right place i.e. in the else part of the "If fs.FoundFiles.Count = 1 Then" statement. Is it to do with a property on the actual list box?

Your problem is that you are constantly adding to the listbox but never removing the existing items.

There are 3 ways you can fix this.

Method 1
Expand|Select|Wrap|Line Numbers
  1. Else
  2.                     'Set value list of the list box to an empty string to clear all values
  3.                     Me.SearchResults.RowSource = ""
  4.  
  5.                     For i = 1 To fs.FoundFiles.Count
  6.  
  7.                     SearchResults.AddItem fs.FoundFiles(i)
  8.  
  9.                     Next i
  10.  
  11.                     multiple = multiple + 1
  12. End If
  13.  
Method 2
Expand|Select|Wrap|Line Numbers
  1. Else
  2.                     'Loop through the listbox and remove existing items
  3.                     Do While Me.List1.ListCount > 0
  4.                             Me.List1.RemoveItem (0)
  5.                     Loop
  6.  
  7.                     For i = 1 To fs.FoundFiles.Count
  8.  
  9.                     SearchResults.AddItem fs.FoundFiles(i)
  10.  
  11.                     Next i
  12.  
  13.                     multiple = multiple + 1
  14. End If
  15.  
Method 3
Expand|Select|Wrap|Line Numbers
  1. 'Declare a string
  2. Dim strRowSource As String
  3.  
  4. strRowSource = ""
  5. Else
  6.                     'Build String
  7.                     For i = 1 To fs.FoundFiles.Count
  8.  
  9.                     strRowSource = strRowSource & fs.FoundFiles(i) & ";"
  10.  
  11.                     Next i
  12.  
  13.                     'Set ListBox rowsource to string
  14.                     SearchResults.RowSource = strRowSource
  15.  
  16.                     multiple = multiple + 1
  17. End If
  18.  
Jan 30 '08 #7

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

Similar topics

3
by: Alfredo Agosti | last post by:
Hi folks, I have an Access 2000 db with a memo field. Into the memo field I put text with bold attributes, URL etc etc What I need to to is converting the rich text contained into the memo...
2
by: Asbjørn Ulsberg | last post by:
Hi. I'm trying to convert Brady Hegberg's great RTF2HTML VB 6.0 module to C#. I've managed to convert the VB code to VB.NET, which gave me the following code: Option Strict On Option...
7
by: jj | last post by:
It seems simple but I had a hard time converting this small function from vb.net to C#. I even tried the software that automatically converts from vb to c# , but to no avail. Please can someone...
1
by: UKuser | last post by:
Hi Guys, I have a program which converts Excel spreadsheets to Javascript and allows interactivity. However it can't convert it to PHP, which is obviously better for users to view (in case J/S...
2
by: XML newbie: Urgent pls help! | last post by:
Does anyone have a snippet of code that will convert a string to a long array? I've nearly smashed my head against the wall trying to figure this out. I'm Using vb.net 2005 Pls reply asap. I...
12
by: Frederik Vanderhaeghe | last post by:
Hi, I have a problem converting text to a double. Why doesn't the code work: If Not (txtdocbedrag.Text = "") Then Select Case ddlBedrag.SelectedIndex Case 0 Case 1
10
by: Ron | last post by:
I want to calculate the surface area of a sphere from an inputed radius with option strict on. I guess I am not converting something correctly. Here is what I am doing: I have a textbox...
3
by: Jef Driesen | last post by:
How can I convert a date string to a number (e.g. a time_t value or a tm struct)? I know about the strptime function, but then I have to know the format string. And that is a problem. I'm trying...
1
by: vcbytes | last post by:
I am having a problem with the following code: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { String^ texts = textBox1->Text; char *text =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.