Loop Through Recordset and Kill

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Mitchell

    Loop Through Recordset and Kill

    I use a function to read all of the files from a couple of directories
    (and subfolders) and update a table(tblfiles) with the fullpath and
    file name, the filesize and the date the file was created. I then
    manually select files to delete by clicking on a yes/no checkbox. I
    have a query (qryfiledelete) which selects all of the files from
    tblfiles where the yes/no field is yes.

    What I want to do is run a function which will delete (Kill?) these
    files from the computer. I have searched google and can find lots of
    examples of how to delete the files and only one : -

    Dim db As Database
    Dim rst As Recordset
    Dim strPathName As String

    Set db=CurrentDb
    Set rst =db.OpenRecords et("qryfiledele te")

    Do Until rst.EOF
    Kill rst!PathName
    rst.MoveNext
    Loop

    But get an error on the Kill line - Compile Error, Expected Variable
    or Procedure, not Project.

    Can anyone see what I am doing wrong?
    Thanks

    David
  • MGFoster

    #2
    Re: Loop Through Recordset and Kill

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    The error seems to indicate that the above code isn't in a procedure
    (Sub or Function). Is it? Else, you are using DAO and don't have the
    DAO Reference selected in the References. Or, rst!PathName may be a
    NULL value. Does the query "qryFileDel ete" have a criteria of
    "PathName Is Not NULL"?

    Rgds,

    MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
    Oakland, CA (USA)

    -----BEGIN PGP SIGNATURE-----
    Version: PGP for Personal Privacy 5.0
    Charset: noconv

    iQA/AwUBQBV9QoechKq OuFEgEQJnNACg4K u94bQeo4swE26ak M4nDwgh5qEAoOdf
    PHMOTzPp8WJHRC9 mLGw4ew3i
    =g8r/
    -----END PGP SIGNATURE-----



    David Mitchell wrote:
    [color=blue]
    > I use a function to read all of the files from a couple of directories
    > (and subfolders) and update a table(tblfiles) with the fullpath and
    > file name, the filesize and the date the file was created. I then
    > manually select files to delete by clicking on a yes/no checkbox. I
    > have a query (qryfiledelete) which selects all of the files from
    > tblfiles where the yes/no field is yes.
    >
    > What I want to do is run a function which will delete (Kill?) these
    > files from the computer. I have searched google and can find lots of
    > examples of how to delete the files and only one : -
    >
    > Dim db As Database
    > Dim rst As Recordset
    > Dim strPathName As String
    >
    > Set db=CurrentDb
    > Set rst =db.OpenRecords et("qryfiledele te")
    >
    > Do Until rst.EOF
    > Kill rst!PathName
    > rst.MoveNext
    > Loop
    >
    > But get an error on the Kill line - Compile Error, Expected Variable
    > or Procedure, not Project.
    >
    > Can anyone see what I am doing wrong?
    > Thanks
    >
    > David[/color]

    Comment

    • tom

      #3
      Re: Loop Through Recordset and Kill

      David,
      Which version of Access are you using?

      I suspect it would help things out if you specify the namespaces of
      your variables. Specifically, you may be getting caught in the ADO/DAO
      headache. I'm a DAO guy, so I'd say do something like this:

      =============== =====
      Dim db As DAO.Database
      Dim rst As DAO.Recordset
      ...
      =============== =====

      You'll need to make sure you have a reference set to the DAO object
      library.
      (Also, it doesn't look like you're using that "strPathNam e" variable
      either.)

      And, make sure to cleanup at the end with:

      =============== =====
      set rst = nothing
      set db = nothing
      =============== =====

      hth,
      -td
      [color=blue]
      > What I want to do is run a function which will delete (Kill?) these
      > files from the computer. I have searched google and can find lots of
      > examples of how to delete the files and only one : -
      >
      > Dim db As Database
      > Dim rst As Recordset
      > Dim strPathName As String
      >
      > Set db=CurrentDb
      > Set rst =db.OpenRecords et("qryfiledele te")
      >
      > Do Until rst.EOF
      > Kill rst!PathName
      > rst.MoveNext
      > Loop
      >
      > But get an error on the Kill line - Compile Error, Expected Variable
      > or Procedure, not Project.
      >
      > Can anyone see what I am doing wrong?
      > Thanks
      >
      > David[/color]

      Comment

      • Ryan

        #4
        Re: Loop Through Recordset and Kill

        If you want to delete the files, have a look at FileSystemObjec t which
        should allow you to do this. I'd have a query I'd run through, find
        the records wanted, get the name and path and then delete using
        FileSystemObjec t.


        tom@nuws.com (tom) wrote in message news:<c17f6324. 0401261258.4b1a e159@posting.go ogle.com>...[color=blue]
        > David,
        > Which version of Access are you using?
        >
        > I suspect it would help things out if you specify the namespaces of
        > your variables. Specifically, you may be getting caught in the ADO/DAO
        > headache. I'm a DAO guy, so I'd say do something like this:
        >
        > =============== =====
        > Dim db As DAO.Database
        > Dim rst As DAO.Recordset
        > ...
        > =============== =====
        >
        > You'll need to make sure you have a reference set to the DAO object
        > library.
        > (Also, it doesn't look like you're using that "strPathNam e" variable
        > either.)
        >
        > And, make sure to cleanup at the end with:
        >
        > =============== =====
        > set rst = nothing
        > set db = nothing
        > =============== =====
        >
        > hth,
        > -td
        >[color=green]
        > > What I want to do is run a function which will delete (Kill?) these
        > > files from the computer. I have searched google and can find lots of
        > > examples of how to delete the files and only one : -
        > >
        > > Dim db As Database
        > > Dim rst As Recordset
        > > Dim strPathName As String
        > >
        > > Set db=CurrentDb
        > > Set rst =db.OpenRecords et("qryfiledele te")
        > >
        > > Do Until rst.EOF
        > > Kill rst!PathName
        > > rst.MoveNext
        > > Loop
        > >
        > > But get an error on the Kill line - Compile Error, Expected Variable
        > > or Procedure, not Project.
        > >
        > > Can anyone see what I am doing wrong?
        > > Thanks
        > >
        > > David[/color][/color]

        Comment

        • Terry Kreft

          #5
          Re: Loop Through Recordset and Kill

          Over kill (sic) for the job.

          Terry

          "Ryan" <ryanofford@hot mail.com> wrote in message
          news:7802b79d.0 401270101.49d34 99d@posting.goo gle.com...[color=blue]
          > If you want to delete the files, have a look at FileSystemObjec t which
          > should allow you to do this. I'd have a query I'd run through, find
          > the records wanted, get the name and path and then delete using
          > FileSystemObjec t.
          >
          >
          > tom@nuws.com (tom) wrote in message[/color]
          news:<c17f6324. 0401261258.4b1a e159@posting.go ogle.com>...[color=blue][color=green]
          > > David,
          > > Which version of Access are you using?
          > >
          > > I suspect it would help things out if you specify the namespaces of
          > > your variables. Specifically, you may be getting caught in the ADO/DAO
          > > headache. I'm a DAO guy, so I'd say do something like this:
          > >
          > > =============== =====
          > > Dim db As DAO.Database
          > > Dim rst As DAO.Recordset
          > > ...
          > > =============== =====
          > >
          > > You'll need to make sure you have a reference set to the DAO object
          > > library.
          > > (Also, it doesn't look like you're using that "strPathNam e" variable
          > > either.)
          > >
          > > And, make sure to cleanup at the end with:
          > >
          > > =============== =====
          > > set rst = nothing
          > > set db = nothing
          > > =============== =====
          > >
          > > hth,
          > > -td
          > >[color=darkred]
          > > > What I want to do is run a function which will delete (Kill?) these
          > > > files from the computer. I have searched google and can find lots of
          > > > examples of how to delete the files and only one : -
          > > >
          > > > Dim db As Database
          > > > Dim rst As Recordset
          > > > Dim strPathName As String
          > > >
          > > > Set db=CurrentDb
          > > > Set rst =db.OpenRecords et("qryfiledele te")
          > > >
          > > > Do Until rst.EOF
          > > > Kill rst!PathName
          > > > rst.MoveNext
          > > > Loop
          > > >
          > > > But get an error on the Kill line - Compile Error, Expected Variable
          > > > or Procedure, not Project.
          > > >
          > > > Can anyone see what I am doing wrong?
          > > > Thanks
          > > >
          > > > David[/color][/color][/color]


          Comment

          • Terry Kreft

            #6
            Re: Loop Through Recordset and Kill

            David,
            Check that you don't have a module called Kill, if you do rename it to
            modKill.

            Then try

            Dim db As DAO.Database
            Dim rst As DAO.Recordset
            Dim strPathName As String

            Set db=CurrentDb
            Set rst =db.OpenRecords et("qryfiledele te")
            With rst
            Do Until .EOF
            strPathName = .Fields("PathNa me") & ""
            if Len(strPathName ) > 0 then
            if Dir(strPathName ) > 0 then
            Kill strPathname
            End if
            End if
            .MoveNext
            Loop
            End With

            Terry


            "David Mitchell" <david.a.mitche ll@talk21.com> wrote in message
            news:c3b0fc6f.0 401260633.344c9 140@posting.goo gle.com...[color=blue]
            > I use a function to read all of the files from a couple of directories
            > (and subfolders) and update a table(tblfiles) with the fullpath and
            > file name, the filesize and the date the file was created. I then
            > manually select files to delete by clicking on a yes/no checkbox. I
            > have a query (qryfiledelete) which selects all of the files from
            > tblfiles where the yes/no field is yes.
            >
            > What I want to do is run a function which will delete (Kill?) these
            > files from the computer. I have searched google and can find lots of
            > examples of how to delete the files and only one : -
            >
            > Dim db As Database
            > Dim rst As Recordset
            > Dim strPathName As String
            >
            > Set db=CurrentDb
            > Set rst =db.OpenRecords et("qryfiledele te")
            >
            > Do Until rst.EOF
            > Kill rst!PathName
            > rst.MoveNext
            > Loop
            >
            > But get an error on the Kill line - Compile Error, Expected Variable
            > or Procedure, not Project.
            >
            > Can anyone see what I am doing wrong?
            > Thanks
            >
            > David[/color]


            Comment

            • Lyle Fairfield

              #7
              Re: Loop Through Recordset and Kill

              david.a.mitchel l@talk21.com (David Mitchell) wrote in
              news:c3b0fc6f.0 401260633.344c9 140@posting.goo gle.com:
              [color=blue]
              > I use a function to read all of the files from a couple of directories
              > (and subfolders) and update a table(tblfiles) with the fullpath and
              > file name, the filesize and the date the file was created. I then
              > manually select files to delete by clicking on a yes/no checkbox. I
              > have a query (qryfiledelete) which selects all of the files from
              > tblfiles where the yes/no field is yes.
              >
              > What I want to do is run a function which will delete (Kill?) these
              > files from the computer. I have searched google and can find lots of
              > examples of how to delete the files and only one : -
              >
              > Dim db As Database
              > Dim rst As Recordset
              > Dim strPathName As String
              >
              > Set db=CurrentDb
              > Set rst =db.OpenRecords et("qryfiledele te")
              >
              > Do Until rst.EOF
              > Kill rst!PathName
              > rst.MoveNext
              > Loop
              >
              > But get an error on the Kill line - Compile Error, Expected Variable
              > or Procedure, not Project.
              >
              > Can anyone see what I am doing wrong?[/color]

              Not opening Explorer?


              --
              Lyle
              (for e-mail refer to http://ffdba.com/contacts.htm)

              Comment

              • David Mitchell

                #8
                Re: Loop Through Recordset and Kill

                Thanks Terry, works perfectly.

                David
                "Terry Kreft" <terry.kreft@mp s.co.uk> wrote in message news:<XIOcnTbLX oCDoovdSa8jmA@k aroo.co.uk>...[color=blue]
                > David,
                > Check that you don't have a module called Kill, if you do rename it to
                > modKill.
                >
                > Then try
                >
                > Dim db As DAO.Database
                > Dim rst As DAO.Recordset
                > Dim strPathName As String
                >
                > Set db=CurrentDb
                > Set rst =db.OpenRecords et("qryfiledele te")
                > With rst
                > Do Until .EOF
                > strPathName = .Fields("PathNa me") & ""
                > if Len(strPathName ) > 0 then
                > if Dir(strPathName ) > 0 then
                > Kill strPathname
                > End if
                > End if
                > .MoveNext
                > Loop
                > End With
                >
                > Terry[/color]

                Comment

                Working...