Suspend Code until function completed.

Henley12

Troy University Fan
Local time
Yesterday, 22:16
Joined
Oct 10, 2007
Messages
222
I have a form that I am using to send emails to our maintenance department when a work order is written. I want my code to automatically spell check a field on the form before it sends the email. I have the call to the spellcheck function on the buttonclick event, but it does not allow it to complete the spellcheck before it actually sends the email. The code is as follows:

Private Sub cmdSend_Click()
If Not IsNull([Department]) Then
Call cmdSpellCheck (this opens the spellcheck box)
>>>>>>>>>>>>I need it to pause here before completing this code
Me![chkSpellCheck] = -1
Me![EmailSent] = -1
DoCmd.RunCommand acCmdSaveRecord
Call send_email
Dialog.Box "Your email has been sent.", vbOKOnly, "Message Sent"
DoCmd.GoToRecord , , acNewRec
Requestor.SetFocus
Else
Dialog.Box "You must enter a department.", vbOKOnly, "Missing Department"
Department.SetFocus
End If
End Sub



Any ideas? Thanks.
 
Normally, VBA can only have one thread at a time, so if you call a function, it will of course branch out to that function and come back. I'm not sure what the function cmdSpellCheck, but if it all does is open the spell check box, then that's why.

1) Is there a option to open it as dialog?
2) Can you have that button modified so it just open the box only and execute the rest of code only when user close the spellcheck box?
 
Hey, Banana -

Your question just suggested a way to do it.

If he creates a form to use to do the spell check - transfer the email text over to it and open the form as dialog and then open the spell check, then transfer the completed text back and continue. That should work.
 
But does a Call command not go to the function being called and complete that function before returning to the calling function?
 
Yes, but as I said, if all it does is open a form, then it's already done its job.

It has no special knowledge whether it's supposed to wait for input, which is why for some form, you need to direct it to open as dialog. This behavior is consistent with any other opening operations.
 
Incidentally, is that spellcheck form a custom form you made or a form you derived from an API or ??
 
It is a spellcheck routine I got off the web. It consists of 4 tables and 2 forms. It is called MS Access Spell Checker.
 
so it's just Access forms then? If so, just modify the function to open it as dialog.
 
Well, good lord, that was easy! Boy, did I make this thing harder than it needed to be. Thanks for all your help.
 
Well, good lord, that was easy! Boy, did I make this thing harder than it needed to be. Thanks for all your help.

Well, Banana IS the TOP BANANA around here :D

banana.jpg
 

Users who are viewing this thread

Back
Top Bottom