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: -
If fs.Execute() = 1 Then
-
-
URL = fs.FoundFiles
-
-
End If
-
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?
6 3302 JKing 1,206
Recognized Expert Top Contributor
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.
Where index is any number from 0 to FoundFiles.Coun t - 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.
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.
Where index is any number from 0 to FoundFiles.Coun t - 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.
JKing 1,206
Recognized Expert Top Contributor
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.
-
-
-
Do Until Form.CurrentRecord = CountDisplay
-
-
'slashfrontpos = InStrRev(URL, "\")
-
'URLLength = Len(URL)
-
'slashbackpos = URLLength - slashfrontpos
-
'Extract = Right(URL, slashbackpos)
-
-
'pointfrontpos = InStrRev(URL, ".")
-
'URLLength = Len(URL)
-
'pointbackpos = URLLength - pointfrontpos
-
'Extension = "*." + Right(URL, pointbackpos)
-
-
If Drive = "" Then
-
Drive = Left(URL, 3)
-
End If
-
-
fs.NewSearch
-
-
With fs
-
-
.LookIn = "C:;D:"
-
.SearchSubFolders = True
-
.filename = Extract
-
.MatchTextExactly = True
-
.Filetype = msoFileTypeAllFiles
-
-
End With
-
-
If fs.Execute > 0 Then
-
-
'If only 1 match was found, amend record, if >1 add file paths to list box
-
If fs.FoundFiles.Count = 1 Then
-
-
URL = fs.FoundFiles(1)
-
ValidPath = -1
-
corrected = corrected + 1
-
-
Else
-
-
For i = 1 To fs.FoundFiles.Count
-
SearchResults.AddItem fs.FoundFiles(i)
-
Next i
-
-
multiple = multiple + 1
-
-
End If
-
-
Else
-
-
none = none + 1
-
-
End If
-
-
'If the current record number = total number of records with invalid file paths
-
'exit sub, if not then go to next record
-
If Form.CurrentRecord = TotalInvalid Then
-
-
If corrected > 0 Then
-
-
If corrected = 1 Then
-
MsgBox corrected & " music file had it's file path corrected automatically."
-
Else
-
MsgBox corrected & " music files had their file paths corrected automatically."
-
End If
-
-
End If
-
-
If multiple > 0 Then
-
-
SearchResults.Enabled = True
-
-
If multiple = 1 Then
-
MsgBox multiple & " music file had more than one match in the search."
-
Else
-
MsgBox multiple & " music files had more than one match in the search."
-
End If
-
-
Overwrite.Enabled = True
-
-
End If
-
-
If none > 0 Then
-
-
If none = 1 Then
-
MsgBox none & " music file had no matches in the search."
-
Else
-
MsgBox none & " music files had no matches in the search."
-
End If
-
-
End If
-
-
Exit Do
-
-
Else
-
-
DoCmd.GoToRecord , , acNext
-
-
End If
-
-
Loop
-
-
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.
JKing 1,206
Recognized Expert Top Contributor
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 -
Else
-
'Set value list of the list box to an empty string to clear all values
-
Me.SearchResults.RowSource = ""
-
-
For i = 1 To fs.FoundFiles.Count
-
-
SearchResults.AddItem fs.FoundFiles(i)
-
-
Next i
-
-
multiple = multiple + 1
-
End If
-
Method 2 -
Else
-
'Loop through the listbox and remove existing items
-
Do While Me.List1.ListCount > 0
-
Me.List1.RemoveItem (0)
-
Loop
-
-
For i = 1 To fs.FoundFiles.Count
-
-
SearchResults.AddItem fs.FoundFiles(i)
-
-
Next i
-
-
multiple = multiple + 1
-
End If
-
Method 3 -
'Declare a string
-
Dim strRowSource As String
-
-
strRowSource = ""
-
Else
-
'Build String
-
For i = 1 To fs.FoundFiles.Count
-
-
strRowSource = strRowSource & fs.FoundFiles(i) & ";"
-
-
Next i
-
-
'Set ListBox rowsource to string
-
SearchResults.RowSource = strRowSource
-
-
multiple = multiple + 1
-
End If
-
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.C ount = 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 -
Else
-
'Set value list of the list box to an empty string to clear all values
-
Me.SearchResults.RowSource = ""
-
-
For i = 1 To fs.FoundFiles.Count
-
-
SearchResults.AddItem fs.FoundFiles(i)
-
-
Next i
-
-
multiple = multiple + 1
-
End If
-
Method 2 -
Else
-
'Loop through the listbox and remove existing items
-
Do While Me.List1.ListCount > 0
-
Me.List1.RemoveItem (0)
-
Loop
-
-
For i = 1 To fs.FoundFiles.Count
-
-
SearchResults.AddItem fs.FoundFiles(i)
-
-
Next i
-
-
multiple = multiple + 1
-
End If
-
Method 3 -
'Declare a string
-
Dim strRowSource As String
-
-
strRowSource = ""
-
Else
-
'Build String
-
For i = 1 To fs.FoundFiles.Count
-
-
strRowSource = strRowSource & fs.FoundFiles(i) & ";"
-
-
Next i
-
-
'Set ListBox rowsource to string
-
SearchResults.RowSource = strRowSource
-
-
multiple = multiple + 1
-
End If
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
field in plain text.
That's because I truncate the string text but if, when I truncate it
there's a rich tag the code following the truncated string is corrupted.
Don't know if it's clear enough.
|
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 Explicit On
Option Compare Binary
|
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 take some precious minutes to help me out.
Thanks
John
Public Function SimpleCrypt( ByVal Text As String) As String
Dim strTempChar As String, i As Integer
|
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 is turned off).
How would I go about converting some of this created code (example JS
below), or is there an easier way to get PHP to do the calculations
itself? I am aware of an excel-server product but this is too expensive
and doesnt actually...
|
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 thaanku all in advance. God bless u.
| |
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
|
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 txtradius that I enter a radius into.
I then have a lable that I want the surface area to be displayed in
called lblsurface
|
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 to autoformat the contents of text entries in a GUI. For
numbers, I'm converting the text representation to the appropriate type
(using atoi, atof, ...) and converting the result back to text with the
correct format (using sprintf). But this does...
|
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 = strToChars(texts);
String^ shiftcs = domainUpDown1->Text;
char *shiftc = strToChars(shiftcs);
int shift = atoi(shiftc);
char *cipher = encCCipher(text, shift);
String^ ciphers = gcnew String(cipher);
textBox2->Text = ciphers;
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |