put subform in allow additions=false when main form has focus

G

Guest

Hi

Main form: vehicles
Continuous subform: DriversVehicles

When the subform has the focus, there's a button on it to set the subform to
allow addtions =true. So the user clicks this to add a new record. If a
user then clicks on the main form whilst there is a "blank" record waiting
for a new record in the subform, how do I set the subform to allow additions
= false? I've tried putting allow additions=false in the subform's lostfocus
and deactivate events but it doesn't work. I also tried putting it in the
main form's on focus event...it didn't work.

Where do I need to put this? The exact code would be very helpful.
TIA
rich

rich
 
G

Guest

Hi, Rich.
Where do I need to put this? The exact code would be very helpful.

In the main form's subform control's OnExit( ) event, try:

Private Sub subfrmCtrl_Exit(Cancel As Integer)

On Error GoTo ErrHandler

Me.Controls("subfrmCtrl").Form.AllowAdditions = False

Exit Sub

ErrHandler:

MsgBox "Error in subfrmCtrl_Exit( ) in" & vbCrLf & _
Me.Name & "form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub

.. . . where subfrmCtrl is the name of the subform control, not the name of
the form that the control uses.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
W

Wayne Morgan

To expand on what Camaro said, the subform isn't "open" in its own right so
it doesn't get the focus or lose the focus as a form. It is in a container
control on the main form called a subform control. This is what gets and
loses the focus. Controls on the subform can get and lose focus, but not the
subform itself.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top