Changing subform properties by code Error

  • Thread starter Thread starter Rick Seltzer
  • Start date Start date
R

Rick Seltzer

I have a database which has been running without a problem for a year. This
problem, which just started, occurs on about half the computers at a
non-profit. On the computers when it occurs, it occurs about 80% of the
time. All computers use Windows XP and Office 2003. All software has been
updated and all programs have been compacted and repaired.

This line of code occurs when the main client form is opened (OnCurrent).
It sets certain rights for editing the form depending the record number.
Me.AllowEdits = False
Me.AllowDeletions = False
Me.sfrClntContact.Form.AllowEdits = False
Me.sfrClntContact.Form.AllowAdditions = False
(another half-dozen) subforms are also referenced accordingly.

The first two lines run OK (changing the main form). However, when it tries
to change any of the subforms the following error occurs: you entered an
expression that has an invalid reference to the property form/report. Run
time error 2455

Sometimes if I exit Access and sign back in, the code works.
It is totally bizarre as the error is intermittent.
I suspect that the subforms are not properly loaded when they are
referenced. However, when the process is not solved by stepping through the
code or letting it sleep.
Any help would be deeply appreciated.
Rick
 
Are these subforms nested within each other, or are they all linked to the
main form? Usually when I have that many subforms, they are on separate tabs
of a tab control.

Because the subform loads first (before the main form), I've run into
similar problems in the past. The way I get around it is that I leave the
SourceObject of the subforms blank until the user selects the tab that the
subform is on. I then set its SourceObject property to the appropriate form
name. I generally do this in the tab controls Change event, where I have a
select case statement that checks the value of the tab control and then looks
to see whether the SourceObject of the subform on that page is populated. If
not, it populates it.

If you do this, you will have to modify the code in your current event to
check to see whether the SourceObject is blank, before you set your subform
properties.

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
First try using bang where it belongs.
Me!sfrClntContact.Form.AllowEdits = False
As with reserved words Access has always been to lenient in allowing "bad"
practices.
Also try compling everything. Sometimes error messages are "referred pain"
(Like your arm, or anything else, hurting when you are having a heart
attack)
 
Since it is happening intermittently, I would suggest that you might be
starting to see the signs of corruption. I would import everything into a
new, blank file and see if that helps. Also, is this a split
Frontend/Backend or is this a self-contained database on a network share? If
it isn't split (with each user having a copy of the frontend on their
machine) then you are likely seeing corruption issues for sure because it is
not a question of IF a database file will corrupt if run over a network in a
non-split configuration, but WHEN it will corrupt.

See here for more about splitting the database (and why):

http://members.shaw.ca/AlbertKallal/Articles/split/index.htm
 
I guess you may be right that you have a timing problem, and the subform may
not be stable (properly opened) at the time when you try to access it. On the
open or load event of the subform you could in stead try to access the main
form by using:

If Me.parent.xxx = yyy Then
etc
End If


Regards
 
Folks: Thank you all your comments and suggestions.
1. I did use decompile on the code -
2. I earlier did import all elements into a new database.
3. I changed the . to bongs
The above did not work
In response to some of your questions.
4. The main form has 12 tabs and 15 subforms (it is a complicated system for
tracking the needs of veterans suing the VA for denied benefits).
5. It is properly broken into a frontend-backend system with the frontends
residing on the local work stations.

6. I also tried the following
The user moves from record to record after hitting a find button. Only one
record at a time is visible to the user.
When I tried to set the offending lines of code after a successful find.
The same error occurs.
strSQL = "SELECT Client.* FROM Client WHERE Client.ID= " & dblID & "; "
Me.RecordSource = strSQL
Me.SetFocus
Me.Requery
Me.AllowEdits = True
'''Below is a condensation of the code
if dblID=1 then
Me!sfrClntContact.Form.AllowEdits = False
Me!sfrClntContact.Form.AllowAdditions = False
else
Me!sfrClntContact.Form.AllowEdits = True
Me!sfrClntContact.Form.AllowAdditions = True
endif

7. Then I moved the code to the subform(s) current event
if me.parent!txtID=1 then
Me.AllowEdits = False
Me.AllowAdditions = False
else
Me.AllowEdits = True
Me.AllowAdditions = True
endif
HOWEVER the code does not trigger after the main form moves to a new record.
I also tried this with Open and Load.
How can I force the subforms current event to trigger?
Thanks again for any help on this matter.
Rick
 
Back
Top