Controlling a Sub Form

P

PosseJohn

I have a form that displays single records. The form has a tab control with
3 tabs.

On the third tab, I have a sub form, that does not allow additions. On that
same tab, I have a command button to add a new record to the subform.

I'm having difficulty adding a new record (i.e. nothing happens).

Main Form Name = frmContacts
Sub Form Name = sfrmContactEntry
Tab Control Name = tabInfo
Tab Name = pageComments
Command Button Name = cmdAdd

Private Sub cmdAdd_Click()
Me.sfrmContactEntry.SetFocus
Me.sfrmContactEntry.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
End Sub

Thank you in advance for showing me the errors of my way...
 
D

Dirk Goldgar

PosseJohn said:
I have a form that displays single records. The form has a tab control
with 3 tabs.

On the third tab, I have a sub form, that does not allow additions. On
that same tab, I have a command button to add a new record to the subform.

I'm having difficulty adding a new record (i.e. nothing happens).

Main Form Name = frmContacts
Sub Form Name = sfrmContactEntry
Tab Control Name = tabInfo
Tab Name = pageComments
Command Button Name = cmdAdd

Private Sub cmdAdd_Click()
Me.sfrmContactEntry.SetFocus
Me.sfrmContactEntry.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
End Sub

Thank you in advance for showing me the errors of my way...


I would expect you to get a compile-time error message with that code, since
the subform control does not have an AllowAdditions property. try this
slightly changed version:

Private Sub cmdAdd_Click()
Me.sfrmContactEntry.SetFocus
Me.sfrmContactEntry.Form.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
End Sub
 
P

PosseJohn

Thank you Dirk, but that did not resolve my problem, the command button
still doesn't function, any other ideas?
 
D

Dirk Goldgar

PosseJohn said:
Thank you Dirk, but that did not resolve my problem, the command button
still doesn't function, any other ideas?

Code like that works just fine for me. Please answer these questions:

1. Do you get an error message? If so, what is it?

2. If you compile the database (in VB Editor, click Debug -> Compile), do
you get an error?

3. Have you verified the name of the subform control, which you are calling
"sfrmContactEntry"? In the code, you must use the name of the subform
control on the (on the main form), which may or may not be the same as the
name of the form object that it displays.

4. What version of Access are you running?

5. Does other VBA code in the database run?

6. If you are using Access 2007 or 2010, is the database in a trusted
location, as defined in the Trust Center settings?
 
P

PosseJohn

I walked thru your questions and when I compiled, I was receiving an error
on the first line...Method or data member not found.

When I change the first line to a note, the second line also gives the same
error.

The program highlights ".sfrmContactEntry"

Your third question was the key to resolving my problem. I changed the name
of the control for the table to match the form name, and walla, the command
button now functions as expected.

Thank you Dirk.
Have a pleasant evening.
 

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