Results 1 to 2 of 2

Thread: Access

  1. #1
    Join Date
    Nov 2003

    Unanswered: Access

    Would like to use the dos find command from Access VB and retrieve the results into a a table.

    I can start the find cmd with shell but how can I retrieve the result into a table. ?

    Thanks for the help.

  2. #2
    Join Date
    Jan 2003
    Rockville, MD
    I'm not sure shelling to the DOS find command is the best way to go.

    Try this sample subroutine instead. It requires the DAO reference library, and assumes:
    • the table you want to save the data to is named "MyTable"
    • the field in that table is named "MyField"
    • the path/filename of the file you want to search through is "C:\MyFolder\MyFileName.txt"
    • the text you want to search for is "TextToSearchFor"
    Make the appropriate changes to reflect your actual needs.
    Sub FindAndAppend()
       Dim lngFile As Long
       Dim rstLinesFound As DAO.Recordset
       Dim strFileName As String
       Dim strSearchText As String
       Dim strTextLine As String
       strFileName = "C:\MyFolder\MyFileName.txt"
       strSearchText = "TextToSearchFor"
       Set rstLinesFound = CurrentDb.OpenRecordset("SELECT MyTable.MyField FROM MyTable;", dbOpenDynaset)
       lngFile = FreeFile
       Open strFileName For Input As #lngFile
       ' Loop until end of file.
       Do While Not EOF(lngFile)
          ' Read line into variable.
          Line Input #lngFile, strTextLine
          ' Check to see if text to search for is contained in line
          If InStr(UCase$(strTextLine), UCase$(strSearchText)) > 0 Then
             'text is found, save it
             rstLinesFound!MyField = strTextLine
          End If
       Close #lngFile
       Set rstLinesFound = Nothing
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts