Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 29th, 2007, 07:29 AM
Authorized User
 
Join Date: Jun 2007
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Interrupt code

Hey there,

I want a button that stops the current code.

eg. I have build a search function but when it searches on a rather large drive then it does not stop before all items are listed. So I would like to have a stop button.

Or does anybody have suggestions how to solve such a thing properly

I know it can be done with send keys "Ctrl Break", but I have noticed that you have to push that frequently before it stops. I can only imagine that you have to push the button frequent before it works. That is not an option imo.

Regards,
Bjorn



 
Old October 29th, 2007, 08:46 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

First what is the code that you are using to send the search? My thinking is that you would put the code in a loop and have the option to send an interupt to the loop. So every time the code loops, it checks for the interupt condition.



mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old October 29th, 2007, 09:12 AM
Authorized User
 
Join Date: Jun 2007
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There you go!

Thanks man!! So basicly at the end of my loop I let vba check if at the form itself something is activated!

Something like

If Forms!FileSearch!Stop.value = 0 Then
: Goto THE_END
End If

THE_END:
End Function

Thanks again, good call

 
Old October 29th, 2007, 09:21 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I think so. The problem might be if the code checks the value once at the beggining on the loop, and then can't check it again until after the sub has run. So within each loop, you will have to take the variable, like you said:

Do Until rs.EOF
     'Check 100 recrds
     If Me.Stop.value = 0 Then
        Exit Sub
        'or package results so far
     End If
Loop

It depends on what search is doing. I would open a recordset and then search 100 records, then check the value, then search 100 more, etc. If the code just executes a search without parsing the records, then it might not work.

So create a table to send results to, then parse 100 records and send results, then check the value, then parse another 100 etc unless the stop value is ancountered. Then close the recordset and open the report of continuous form on the results accumulated so far, along with a record comparison, like 80,000 of 500,000 records searched kind of thing.



mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old October 29th, 2007, 09:23 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Man, lots of spelling mistakes there. I am fat-fingered today.

mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old October 29th, 2007, 09:40 AM
Authorized User
 
Join Date: Jun 2007
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Does not work.... I cannot change the form while the code runs.

 
Old October 29th, 2007, 09:46 AM
Authorized User
 
Join Date: Jun 2007
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well I am doing this, kinda complicated... Maybe a bit onconventional and sloppy but I am learning.

I set a drive, wich i let search.
Then it returns the outcome on a form
On the form you can choose to search the whole drive or just the root
When you go for the whole drive, i drop it in a loop and let check table for duplicates.

Public Function GetFiles()


Dim Naam, Naam2, table_name, Veld, path, NieuwPad, Cur_Form, KB1, KB2, Zoek1, Zoek2, Pos
Dim AC_LIST As Recordset
Dim oFSO As Object
Dim folder As Object
Dim subfolders As Object
Dim GrooteFile As Double
Dim GrooteFolder As String

NieuwPad = 0

ZOEKEN:

    If NieuwPad = 0 Then

        If IsNull(Forms!F_Get_Files!DRIVE) Or (Forms!F_Get_Files!DRIVE) = "" Then
            path = "H:"
        Else
            path = Forms!F_Get_Files!DRIVE & "\"
        End If
            table_name = "Get_Files"
            Cur_Form = "F_Get_Files"

   Else
   path = NieuwPad
   End If

    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set folder = oFSO.GetFolder(path)
    Set subfolders = folder.subfolders
    Set AC_LIST = CurrentDb.OpenRecordset(table_name)

    DoCmd.GoToRecord acDataForm, (Cur_Form), acNewRec

On Error GoTo err_mgr
For Each i In subfolders
    Forms!F_Get_Files!Pad = "Folder op " & (path) & "" & Mid(i, 1 + InStrRev(i, "\"), Len(i) + 1 - InStrRev(i, "\"))
    Forms!F_Get_Files!Naam = "<KLIK HIER OM DEZE FOLDER TE SELECTEREN OM TE SCANNEN>"

        If Forms!F_Get_Files!Check36.Value = True Then
            GrooteFolder = i.Size


                 If IsNull(GrooteFolder) Or (GrooteFolder) = "" Then
                     GrooteFolder = 0
                 Else
                  KB2 = Format(GrooteFolder / 1024, "##,###")
                         If IsNull(KB2) Or (KB2) = "" Then
                     KB2 = 0
                     Forms!F_Get_Files!Naam = "<DEZE FOLDER IS LEEG>"
                        End If
                    End If
                Forms!F_Get_Files!KB = (KB2)
        End If


    DoCmd.GoToRecord acDataForm, (Cur_Form), acNext

 Next

        Naam = Dir(path)
: GoTo FirstLoop

        Do Until Naam = ""
        Naam = Dir
        File = (path) & (Naam)
FirstLoop:
        Exten = Right(Naam, 3)

        If Forms!F_Get_Files!Check36.Value = True Then
            If Naam = "" Then
                GrooteFile = 0
            Else
                GrooteFile = FileLen(File)
                KB = Format(GrooteFile / 1024, "##,###")
                    If IsNull(KB) Or (KB) = "" Then
                        KB = 1
                    End If
            End If
        End If

    If IsNull(Naam) Or (Naam) = "" Then
: GoTo Weiter_machen
    Else
    Forms!F_Get_Files!Pad = "File op " & (path) & Mid(i, 1 + InStrRev(i, "\"), Len(i) + 1 - InStrRev(i, "\"))
    Forms!F_Get_Files!Naam = (Naam)
    Forms!F_Get_Files!Ext = (Exten)
    Forms!F_Get_Files!KB = (KB)
    DoCmd.GoToRecord acDataForm, (Cur_Form), acNext
    End If


Loop
Weiter_machen: 'Jawohl her commandant Bjorn
If Forms!F_Get_Files!GEHELE.Value = True Then
'msg = MsgBox("DONE")

    Set AC_LIST = CurrentDb.OpenRecordset(table_name)

            With AC_LIST
            Aantal = .RecordCount
            Do While Not .EOF

            Sjaak = DLookup("[Klaar]", "Q_MORE", "[Klaar] = 0")


            If Sjaak <> 0 Then
: GoTo THE_END
            End If


                Pad = .Fields![Pad]
                Naam2 = .Fields![Naam]
                Klaar = .Fields![Klaar]

    If Naam2 = "<KLIK HIER OM DEZE FOLDER TE SELECTEREN OM TE SCANNEN>" And Klaar = False Then

                .Edit
                ![Klaar] = True
                .Update

        Lengte = Len(Pad)
        NieuwPad = Mid(Pad, 11, Lengte) & "\"
        path = NieuwPad

' Begin opnieuw - ZOEKEN Begint weer van start positie
: GoTo ZOEKEN

    End If

    If Forms!F_Get_Files!Stop.Value = True Then
: GoTo THE_END
    End If

    .MoveNext
    Loop
    End With

End If



err_mgr:
    erreur = Err
' MsgBox Err & " - " & Err.Description
    Resume Next
    If Err = 70 Then Resume Next
    'Stop
    'Resume Next
THE_END:

DoCmd.Close ("F_Stop")
msg = MsgBox("DONE!")

End Function



 
Old October 29th, 2007, 12:06 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

It looks like you are recursing folders and subfolders here, and this would be the place to add code to count to 100, and then check the value on the form. I would do something like this, after adding a text box to display the number of records counted so far.

Do you need help with the actual code?





mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old October 29th, 2007, 02:18 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Can you change the form if the code runs on a module? Also, can you pause the code for one/half second each loop to check the state? Use a toggle button.

mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old October 30th, 2007, 02:52 AM
Authorized User
 
Join Date: Jun 2007
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I was thinking yesterday night... I always have the same procedure, I go fetch the (root) dir (and files) and then fetch all subfolders (and the files per folder), mark them in a table as fetched. And when fetched all it starts again with the first new root found. So on and on till every folder is scanned.

So my idea is to after the last subfolder is scanned and before it sets a new (root) folder to build in a moment of rest. Like you said. I let him count the items and that is my total and then do a (For i = number to .recordcount) ,,, like you mentioned here. Let the tool run then reset the root and counter. So basicly in stead of 100, the new root folder is my point of rest.

I think that has a good change of succes. I will figure that out today.

Thanks for input

This is a good way to learn vba





Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent:hard disk serial code and vb code ivanlaw Pro VB 6 0 July 25th, 2007 04:05 AM
How to interrupt processing the LOOP in ASP.NET Dmitriy ASP.NET 2.0 Professional 2 November 29th, 2006 12:19 PM
How to interrupt processing the LOOP in ASP.NET Dmitriy General .NET 2 January 13th, 2006 08:43 AM
How to interrupt processing the LOOP in ASP.NET Dmitriy ASP.NET 1.0 and 1.1 Professional 2 December 15th, 2005 04:16 PM
How to interrupt processing the LOOP in ASP.NET Dmitriy Classic ASP Professional 0 December 13th, 2005 08:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.