form not recognised

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi. I have used the following code to try and change the AllowDeletions
property to true:

If Me!txtpass = "pass" Then
DoCmd.Close acForm, "frmrtnpass"
Forms!sbfrmTransactionDetails.AllowDeletions = True

When I run it, an error occurs telling me that it doesn't recognise the
subform. But I have checked and it does exist, I even tested it by
docmd.openform "sbfrmTransactionDetails"

I want the code to grant the user to be able to delete records...

Any help is appreciated.
Thanks
 
When a form is being used as a subform, you can't actually refer to the form
by name: it's not actually in the Forms collection.

Instead, you need to go through the Parent form:

Forms!NameOfParentForm!NameOfSubformControl.Forms.AllowDeletions = True

Note that depending on how the form was added as a subform,
NameOfSubformControl may not be the same as the name of the form being used
as a subform.
 
I thought it was classed as a type of form because it is in my 'Forms' list
and able to write code for it. I tried the code you gave me and that didn't
work either, it said it couldn't find the parent form then.

Do I have to define the form in the code?
 
I guess when you wrote that it is in your Forms list, you referred to the
"Forms" container as seen in the Database Containers window.

Note that the Forms Collection in code (different from the Forms containers)
only consists of Forms *currently open* in your database, not all Forms in
your database. Since you open only the "Parent" Form in normal usage (and
Access processes and displays the Subform as a Control on the "Parent" Form)
and not the Subform, the Subform in not "officially" open and therefore it
is not in the Forms collection ...

If the "Parent" Form is "frmrtnpass" then in your code (as posted in the
first post), you have just closed this Form and therefore it is no longer in
the Forms collection as explained in the preceding paragraph.
 

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

Back
Top