Perform task mid-sub proceedure (1 Viewer)

bob bisquick

Registered User.
Local time
Today, 08:46
Joined
Nov 8, 2002
Messages
37
I have some code...
It's running... tra la la...
I get to a point...

If[CountOfDuplicateClients] > 0 Then
DoCmd.OpenForm "DuplicateClientList", acNormal
Else

Continue on with the code....

When the form DuplicateClientList opens, the user has the option to delete the duplicate clients. When the use clicks on the delete button I want to delete the clients (easy) but then I want the code to pick up where it left off (at the 'else' point).

I tried creating a Sub around the If statement, but I could not make it point back to the sub from the 'Delete Clients' button I created.

Help!
 

AlanS

Registered User.
Local time
Today, 08:46
Joined
Mar 23, 2001
Messages
292
There are two problems with the way you have it:
1. Using the IF THEN ELSE construct, Access will always open the form OR execute the subsequent code, but never both.
2. Since you are opening the form asynchronously, the code following the IF THEN ELSE block will run immediately, which is probably not what you intend.

Try this instead:

If [CountOfDuplicateClients] > 0 Then
DoCmd.OpenForm "DuplicateClientList", acNormal, , , , acDialog
End If

Opening the form as a dialog box suspends processing of the calling routine until the form is closed. Removing the ELSE part ensures that the subsequent code will run regardless of whether or not the form is opened.
 

bob bisquick

Registered User.
Local time
Today, 08:46
Joined
Nov 8, 2002
Messages
37
I will try that, thank you very much...

Further to the question... OK, so I am working on my import clients form. The code catches duplicates, so my duplicate clients form opens up (as a dialog). This form lists the duplicate clients. The user then has the option delete the duplicate clients (and this is where I want to jump back into the code), or to cancel. If the user cancels, I don't want to jump back into the code. How do I stop the code from continuing...

Can I close the form the code is associated with (my original import form), or is there a way I can issue a STOP or CANCEL command from with in code?
 

AlanS

Registered User.
Local time
Today, 08:46
Joined
Mar 23, 2001
Messages
292
On the import clients form, place a hidden text box. In the duplicate clients form, set the value of that text box before exiting the form, with the specific value indicating whether or not you want the import clients form to continue processing. Back in the import clients form, test the value of that text box and then proceed accordingly. For example:

'this code appears in the import clients form
Me.txtFlag = ""
If [CountOfDuplicateClients] > 0 Then
DoCmd.OpenForm "DuplicateClientList", acNormal, , , , acDialog
End If
If Me.txtFlag = "Finish" Then Exit Sub

'this code appears in the duplicate clients form
Forms!ImportClientsForm!txtFlag = IIf([appropriate condition here], "Finish", "")
 

Users who are viewing this thread

Top Bottom