How to halt vba code while a form is open

PNGBill

Win10 Office Pro 2016
Local time
Tomorrow, 05:11
Joined
Jul 15, 2008
Messages
2,271
Access 2010. Here is an extract of vba code
Code:
If LoanTotToPay <= 2 Then
        Response = MsgBox("Loan Appears to be Completed. Do you want to check for Late Fees ?", vbYesNo)
            If Response = vbYes Then        'total is less then K2. Give option to check for Late Fees
                stDocName = "FrmLateFeeManage"
                stLinkCriteria = "[LDPK]=" & CStr(LoanRef)
                DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria, , acDialog
            End If
            'Operator choose not to check for Late Fees
    End If

The idea is to have the code halt while form FRMLatefEEManage is open. The form needs to be usable.
When form is closed, the code can continue.

The form opens but isn't full size and doesn't behave as it normally does.

Is acDialog the only method to have the code halted while the form is open ??
 
acDialog will prevent the code from running because it is essentially treating that form like a message box, it is expecting some type of return and will wait until it is closed, however you won't be able to switch between that form and another form using that method.

or you could write a loop to say something like

Code:
do while (syscmd(acSysCmdGetObjectState,acform,"formName")<>0)
   doevents
loop
 
Got around the issue.

When the 2nd form opens you have a command button that calls a function to calculate the amount of Late Fees due.

In the code I call this function and then check if the result is <>0 and if so, open the 2nd form as normal and close the code.
You use the 2nd form and when that is closed you are returned to the original form where you can click for the original function to run.
Should this code decide to check again for Late Fees the result will be Zero and no need to open the 2nd form again.

What would be good is a way of when the 2nd form is opened by calling a function a public variable or something else is effected so that when the form closes, the original code starts again rather then you needing to clik a command button on the 1st form.
 
Any commennts on the idea of using TempVars to handle the halting of code.

In my example I am looping through a recordset and where required the code calls another function to check on a Status and retrun a result.
The main code then compares the returned string.

But... while in the 2nd function we may be required to use a form to decide on an issue.
Problem is that while we are doing that the main code has rushed ahead with the next part of the loop :eek:

What if I created a TempVar with a Value and while tha exists the code can count to 10,000,000, by looping and checking the tempvar each time, and then ask if it can stop now.
When the 2nd function has done it's job, the TempVar value is changed and the counting will stop (hopefully)

Is this a lot of mucking around ??:confused:

Another option could be to use a TempTable and load the recordset into same.
Have the code stop with each Form Activity and when the code is reactivated the TempTable will be able to allow the code to restart where it last stopped:confused:

Appreciate any guidence.
 

Users who are viewing this thread

Back
Top Bottom