Connecting Tech Pros Worldwide Help | Site Map

URGENT - VBA Code to wait until Form Closes

Newbie
 
Join Date: Sep 2007
Posts: 21
#1: Nov 12 '07
I'm trying to complete some changes to a database that I have created and I need to finish it by tomorrow morning!

Here's the situation:

I have a form where people can order a number of products. They can set this form to varying statuses so that their supervisors can review the orders before they get placed. When the user (call them technicians) sets the order form to "review" status, the code goes through each individual item that they have ordered and checks to see if it has a serial number (thus making it a serialized item) because technicians need to enter additional information for all serialized equipment.

When it comes to a serialized item, the code opens up another form and goes to that specific items record so that the technician can edit the item-specific information.

Problem: I want the order form to cycle through these ordered items, but I need it to wait until they have closed that form that opens up for additional information before it continues on to the next item because sometimes there are multiple serialized items on one order.

Currently, it successfully goes through all of the items and identifies whether or not they are serialized items, but it goes through them all and opens up the same form for each serialized item before the user gets to put in data so it ends up with them only being able to enter data for the last serialized item.

Here is my current code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub StatusID_AfterUpdate()
  2. If StatusID = 5 Then
  3.     lbSerials.Requery
  4.     For x = 0 To lbSerials.ListCount - 1
  5.         If lbSerials.Column(2, x) <> "" Then
  6.             MsgBox "You have selected a Serialized item that requires Production Information.", vbInformation, "Production Information Required"
  7.             DoCmd.OpenForm "Production", , , "[SerialNumber]= " & "'" & lbSerials.Column(2, x) & "'"
  8.  
  9. '<Need something here to make it wait?>
  10.  
  11.  
  12.         End If
  13.     Next x
  14. End If
  15.  
  16. End Sub
I use lbSerials as a listbox that pulls in the serial numbers for all of the products in the order form. Then the code checks the correct column (2) of the listbox for all serialnumbers.

Any help is much appreciated!

~Luke
missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 2,997
#2: Nov 12 '07

re: URGENT - VBA Code to wait until Form Closes


I believe when you open the second form, if you set the WindowMode parameter (I think it's the 6th argument) of the OpenForm command to acDialog Access will halt execution of the code until the second form is closed. acDialog sets Modal and Popup Properties to Yes and a form set to Modal, I believe, requires action and closing before other code continues.

Linq ;0)>
Newbie
 
Join Date: Sep 2007
Posts: 21
#3: Nov 12 '07

re: URGENT - VBA Code to wait until Form Closes


Perfect! Works like a charm. Thanks!
missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 2,997
#4: Nov 12 '07

re: URGENT - VBA Code to wait until Form Closes


Glad we could help!

Linq ;0)>
Reply