Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reference control in subform in dcount criteria

Status
Not open for further replies.

xentaur

Programmer
Nov 17, 2003
35
AU
Resident Gurus

The following is a true story, only the form names have been changed to protect your sanity.

- have a form (frmA)with a private sub that is called each time a control on the form is updated.

- Data from the form is in a table (TblA) and is allowed to store duplicate data.

- The sub on frmA does a dcount to check if there is a duplicate record in the underlying table and, if so, displays a message to that effect.

if dcount("[recnum]","TblA","[recnum]=[forms]![FrmA]![recnum])>1 then msgbox "duplicate exists",vbokonly

I'm amalgamating the forms in my database onto one main form (FrmMain) and each form has its own page within FrmMain.

The Problem:

When opened as a standalone, FrmA correctly references the control recnum. However, when opened as a subform on a page in FrmMain I get the message:
"The object doesn't contain the Automation object Forms!FrmA!recnum"

I've tried various and sundry methods and wordings to reference the control , the longest one would be this:

Forms!FrmMain!Page2.Forms!FrmA!recnum.

Alas, all to no avail.

Curiously (for me at least) Everything else in FrmA private sub references as me.control with no problems. It is only this dcount procedure that's being a right royal P in the A.

And so I throw this question out to the void.

help me, dear Gurus. Bathe me in the light of your infinite knowledge and wisdom and chocolate sauce.

Cheers

xentaur.
 
Since a subform isn't recognized as an open form, referencing it as such, will fail. I try not to use dual purpose on forms. To reference subform controls, one need to reference thru the main form:

[tt]forms("mainform")("subformcontrolname").form("txtControl")
' or use the Me keyword
Me("subformcontrolname").form("txtControl")[/tt]

- dot/bang (./!) syntax can of course also be used.

The reference uses the subform control name, which might differ from the subform name as viewed in the database window. See How to refer to a control on a subform or subreport in Access 2000

But, wouldn't

[tt]if dcount("[recnum]","TblA","[recnum]=" & Me![recnum])>1 then[/tt]

work if you're using it from this form?

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top