Subform Visible after ID Created

nate

Registered User.
Local time
Today, 00:54
Joined
May 19, 2010
Messages
29
I have a frmOrders with a subfrmOrderDetails, currently set up so that the sub form is invisible if the main form has a null ID, so when the users open to a new record they can't jump straight into adding things to a non-existent OrderID.

The code for the form is

Private Sub Form_Current()
If Me.NewRecord = False Then
Me.Order_Details_Subform.Visible = True
Else
Me.Order_Details_Subform.Visible = False
End If
End Sub

Private Sub OrderID_AfterUpdate()
If Me.MyCombo <> "" Then
Me.Order_Details_Subform.Visible = True
End If

End Sub

What I would like is the sub form to refresh and become visible as soon as an ID is created. Takers?
 
Hi nate

You may likr to try this.

Put this in the form's "On Dirty" event:
Code:
Me.Order_Details_Subform.Visible = Me.Dirty
 
On the face of it, your second bit of code
Private Sub OrderID_AfterUpdate()
If Me.MyCombo <> "" Then
Me.Order_Details_Subform.Visible = True
End If

End Sub
doesn't seem to make sense, given your request. What does the MyCombo control have to do with the OrderID control? Did you copy this code from somewhere and forget to change MyCombo to OrderID?

Also, only checking for a Zero-Length-String as you do with

If Me.MyCombo <> ""

is not going to help if the field is simply Null, which is much more likely to be the case. At any rate, the normal code, to accomplish your stated goal, would be
Code:
Private Sub OrderID_AfterUpdate()
   If Nz(Me.OrderID, "") <> "" Then
       Me.Order_Details_Subform.Visible = True
   End If
End Sub

This checks for both Null and a ZLS.

You'll also need to have this code in the Form_Current event.

Linq ;0)>
 
Haha I did copy the code, thanks for the help.

However, I still have the difficulty of the subform remaining invisible after the ID has been created....
 
Bob's code will make the subform Visible when anything is entered in the Order Form Record, not just when an OrderID is entered. And it makes no allowance for the formatting persisting when you move to a New Order Record. If you enter a new Order Record with an OrderID, the subform is Visible. If you go to another New Order Record, using his code, the subform will still be Visible, whether you have filled in the OrderID or not.

Linq ;0)>
 
How is the OrderID created? Is it typed in or is it being created thru code? Can you copy the exact code and paste it here?
 
The OrderID is auto-numbered, and appears on the form in a locked text box. A new record is created when any field on the form is filled in.
 
Okay, that's the problem! When a Control isn't populated physically, i.e. thru typing data in, pasting data in or making a selection from a Combobox, the Control's events, such as AfterUpdate, are not executed, so you'll have to explicitly Call the event.

Leaving the two pieces of code I gave you above in place, add this in the Form's Dirty event:
Code:
Private Sub Form_Dirty(Cancel As Integer)
 Call OrderID_AfterUpdate
End Sub
Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom