can it be done

itsglitzy

Registered User.
Local time
Today, 00:50
Joined
Nov 12, 2004
Messages
30
If I have a declared variable lets say “tuesdaydata”

And I get random text files put in a drive lets say 123.txt, 548.txt etc etc

But some of these files have “tuesdaydata” within the text files as a title is there code that will let me on my form opening go and look through the text files and match the “tuesdaydata” and return the text file name ??

Its sounds v complicated and it probably is but can it be done

thanks to all who post any feedabck is good, im a n :confused: ewbie,
 
Pass the path of the text file and the string to search for into this function.

Code:
Public Function Read(ByVal FilePath As String, ByVal SearchString As String) As Boolean
    On Error GoTo Err_Read
    Dim strTemp As String
    Open FilePath For Input As #1
       While Not EOF(1)
            strTemp = Input$(LOF(1), #1)
            If InStr(strTemp, SearchString) Then
                Read = True
            End If
        Wend
    Close #1
    Exit Function
Err_Read:
    Read = False
End Function
 
amazing

thnks very much for posting to my reply butbim a total newbie :o
so and havent got aclue when yous ay about strings etc

my path name is s:\macros and the variable s ain the text file are "a,b,c"

does this make any sense to you ?? pleeeeeeeees help and thnaks very much again :confused:
 
Copy the code above into a new module in your database.

Create a new form (for testing purposes).

On the form put a textbox (call it txtSearchString)
On the form put a textbox (call it txtFilePath)
On the form put a command button (call it cmdSearchText)

Find the command button's Click() event, hit the button at the end of it with the three dots and select Code Builder. You shoudl now see this:

Code:
Private Sub cmdSearchText_Click()

End Sub

Between these two lines put this:

Code:
If Read(Me.txtFilePath, Me.txtSearchString) = True Then
    MsgBox "The search text was found.", vbInformation
Else
    MsgBox "The search text was not found.", vbInformation
End If

Save this form as frmTest.

Now, open the form and in txtFilePath put the full path of one of your text documents.

i.e.

s:\macros\123.txt

Then, in txtSearchString put the text you want to search for:

e.g.

tuesdaydata


Once you have these in the textboxes press the command button.

Did it work?
 
or:

Code:
strFilePath = "C:\"
strFilename=""
strFilename = dir$(strFilePath & "*tuesdaydata*.txt",63)
do until len(strfilename="")
'---- print matched filename to the immediates window
  debug.print strfilepath & strfilename

'---- not sure whether this is needed but I put it in just incase
  strfilename=""

'---- get the next matching filename of "" if not
  strFilename = dir$
loop

Or something like that - read up on dir$ / dir
 
Ah! I read it that tuesdaydata was included in the text file as a field title and not as part of the actual text file's name. :o
 
you guys

thnks v much for all your help, your the best ill let you know if it works, in minute
 
massive respect

that worked superbly sj mcnabey thanks for breaking it down for me this way i learn smoething new aswell, you are the man, now lets dig a bit deeper lets say you wanted to look through a directory "P:\TAS\rja01\" look through all the text files and when the variable matched ie "sz1" it would return in a text box, which file ie "fileA.txt" this var was in....again im being cheeky but it seems so complicated and you guys make it look so easy thanks again and i hope you can help :o
 
Last edited:
I can't offer any advice on how to do this in Access, as this is way above my head too.

But can you not just use the standard Windows search facility (i.e Start|Find files or folders...) to find any text files containing the contents of your variable? There are advanced options for "containing text..." etc.

Dunno, depends on if it is really needed for your db or not.
Just a suggestion.

Or perhaps there is a way to call this search dialog, anyone?
 
what you guys have helped with any is great i thought that was a bit much thanks for posting any way
 
geko said:
But can you not just use the standard Windows search facility (i.e Start|Find files or folders...) to find any text files containing the contents of your variable?

But Windows can't put it in a textbox for him.

Sure, glitzy, its possible. When I get a chance I'll have a stab at it.
 
again

thanks alot and your right it cant return in a text box, well if you manage ill be very greatful thanks, if you bdont still thanks for all your help :)
 

Users who are viewing this thread

Back
Top Bottom