Is this a bug or am I just going insane!

  • Thread starter Willem van der Berg
  • Start date
W

Willem van der Berg

I've been working for about three days now to fix a problem that I do not
find particularly logical. I am more or less a beginner with Access though,
so I'm hoping a more experienced user can help me determine how to solve my
problem. I'll explain.

I've got a tblSupplierPurchases table with purchases from my suppliers. I've
made a frmParametersForm which allows the user to input certain parameters,
like date ranges, name of supplier etc. This form has a command button which
triggers another form. I'll call this one frmSupplierPurchasesForm. The
command button on frmParametersForm writes the parameters into global
variables. frmSupplierPurchasesForm gets it's information through
qryShowSupplierPurchases, this parameterquery contains all the fields of
tblSupplierPurchases and the parameters in the variables.
frmSupplierPurchasesForm shows me the records based on the user's
parameters.
And added twist is that I like to keep 'adding new purchases' and 'show
purchases' as seperate activities, but I use the same
frmSupplierPurchasesForm to do both activities: it's standard properties are
set to add new purchases (AllowAdditions, AllowDeletions, AllowEdits,
DataEntry, NavigationButtons, Caption). There's a subform control on this
form which shows the actual products that belong to the PurchaseID.
When I want to use the form just for showing results, I change the mentioned
proporties through the command button to reflect this change of purpose.

Here's my code:
NumberOfResults = DCount("PurchaseID",
"qryShowSupplierPurchases")
If NumberOfResults > 0 Then
Form_frmSupplierPurchasesForm.RecordSource =
"qryShowSupplierPurchases"
Form_frmSupplierPurchasesForm.AllowAdditions = False
Form_frmSupplierPurchasesForm.AllowDeletions = True
Form_frmSupplierPurchasesForm.AllowEdits = True
Form_frmSupplierPurchasesForm.DataEntry = False
Form_frmSupplierPurchasesForm.NavigationButtons = True
Form_frmSupplierPurchasesForm.lblTitle.Caption = "Show
Purchases"

Form_frmSupplierPurchasesForm.SubFormControl.Form.AllowAdditions = True

Form_frmSupplierPurchasesForm.SubFormControl.Form.AllowDeletions = True
Form_frmSupplierPurchasesForm.SubFormControl.Form.AllowEdits
= True
Form_frmSupplierPurchasesForm.SubFormControl.Form.DataEntry
= False

Form_frmSupplierPurchasesForm.SubFormControl.Form.NavigationButtons = False
Form_frmSupplierPurchasesForm.SetFocus
Else
(MsgBox etc. etc.)
End If

Now, the problem is that I've been getting the run-time error 2455: You
entered an expression that has an invalid reference to the property
Form/Report with
"Form_frmSupplierPurchasesForm.SubFormControl.Form.AllowAdditions = True"
highlighted. I can't really see anything wrong with this code, it has run
before without problems but now it will always give the error.
I have checked all my tables, queries and forms and I can't see anything
wrong with it. The reason why I think there's an Access bug at work is
because when I have picked the parameters and run qryShowSupplierPurchases
manually, it returns the results as expected. Not surprising, as
NumberOfResults checks this as well. I can't work out why the
frmSupplierPruchasesForm won't show the results though...

I have checked the internet for any similar problems, found them, which made
me believe there's a bug at work, but I've never seen the solution... I run
Windows XP Home, use Access 2000 and I have SP3 installed and the latest
version of the Jet engine.
If I have made a mistake (don't point out typo's, I use Dutch names in the
actual database) I would really like to know how to fix it. If there's
indeed a bug at work I would like to know how to work around it.

Any help would be greatly appreciated!!! Thanks in advance. As I said, I'm a
relative beginner and these kind of problems seriously undermine my
confidence in working with Access :(

Best regards,
Willem van der Berg.
 
D

Dan Artuso

Hi,
The usual way to reference things is:
Forms!frmSupplierPurchasesForm.SubFormControl.Form.AllowAdditions = True

I always thought the the syntax Form_someform
was a reference to the form's code module.

See if that helps.
 
A

Albert D. Kallal

Where did you learn that TERRIBLE CODING PRACTICE of referencing the base
form object?

Do not use
Form_frmSupplierPurchasesForm

You can use:

forms!frmSuppierPurchaesForm

Or, you can use:

forms("frmSupplierPurchasesForm").

You DO NOT WANT to use the base class form object. If you have more then one
instance of the form loaded, then which form are you referring to?

If further, if the form is NOT opened, then referencing the base object
means that the form loads, and even the on-open events etc are fired, and
that is totally un-expected behaviour. Use the forms collection for
REFERENCING the form.

Even worse is using the base object of a form when it is ALSO used as a
sub-form. In that case, the reference actually refers to the sub-form, but
if you load the form, the SAME reference now refers to the loaded copy, and
NOT the loaded sub-form. (to be fair, you are NOT referring the sub-form
directly as a form object...but you can do this, but wind up with the
reference problem.

So, my suggestion to avoid use of the base form object may not fix your
problem, but you are asking for all kinds of trouble. I would *really* AVOID
the use that base class object. Further, if your form does NOT have any code
(ie: is a lightweight form), then a base form object does NOT even exist,
and you can't use the above form object anyway.
 
K

Ken Snell

Good luck. You're welcome, from all three of us! And we thank you for your
kind words.
 

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