Subform - Add New Record

  • Thread starter Thread starter Peter Smith
  • Start date Start date
P

Peter Smith

Hi

I need to code a button on my main form to set my subform to open in 'add
new record' mode. I have tried the helpfiles etc but ain't getting
anywhere.

Any help appreciated.

- Peter
 
Hi

I need to code a button on my main form to set my subform to open in 'add
new record' mode. I have tried the helpfiles etc but ain't getting
anywhere.

Any help appreciated.

- Peter

Is this really a Subform, in a subform control? If so, you don't
"open" it - it's just there on the form. In order to have the subform
on the new record you could use code like

Private Sub cmdGoToNew_Click()
Me.subMySubform.SetFocus
DoCmd.GoToRecord acNewRecord
End Sub

where subMySubform is the Name property of the subform *control*
(which isn't necessarily the same as the name of the form within that
control).

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
John Vinson said:
Private Sub cmdGoToNew_Click()
Me.subMySubform.SetFocus
DoCmd.GoToRecord acNewRecord
End Sub

Excellent. I had to change that to acNewRec (must be for A97) but it works
great - thanks so much. One other thing-

When I was using a pop-up form for dataentry, I could use the OnClose event
to check for saving ('if Dirty' before going back to switchboard). How is
it best to do this on a subform as it doesn't close when you move off it to
a different tab?

- Peter
 
Excellent. I had to change that to acNewRec (must be for A97) but it works
great - thanks so much. One other thing-

When I was using a pop-up form for dataentry, I could use the OnClose event
to check for saving ('if Dirty' before going back to switchboard). How is
it best to do this on a subform as it doesn't close when you move off it to
a different tab?

- Peter

You can use the BeforeUpdate event of the Subform control. It only
fires if a record on the subform is dirtied and subsequently you try
to save it (say by moving off the subform).

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
Back
Top