By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,188 Members | 832 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,188 IT Pros & Developers. It's quick & easy.

referencing subform on tab from main form

P: 65
I am working on a form to edit student field placements. the student is selected from a combo box (cboStudent) which then populates a list box(lstPlacements) with field placements for that student. the fields are on a subform (sfrmEntryPlacements) which populate based on which placement is selected from lstPlacements. sfrmEntryPlacements is on a tab, tabFE, which is on main form frmStudentData. lstPlacements is on tabFE but not on sfrmEntryPlacements. I have a box on sfrmEntryPlacements which is either visible if a related table is null, or not visible.

everything works fine except referencing the visible/hidden box from the lstPlacements_OnClick event. I get the error message "can't find form" for given value. i have tried many different combinations and am not sure how to properly reference the variable.

i believe my confusion is over lstPlacements being on the tab. Is the tab considered a subform or part of the main form? I will gladly clarify any confusion over my post.

thanks in advance

code:

Private Sub lstPlacements_Click()
'check if school has contact or not
Dim intCheckContact As Integer
intCheckContact = cboSchool

'if contact null show box
If IsNull(DLookup("[contactid]", "School", "[schoolid] = " & intCheckContact)) Then
Forms!frmStudentData.sfrmEntryPlacement.lblContact Check.Visible = True
'if contact not null, hide box
Else
Forms!frmStudentData.sfrmEntryPlacement.lblContact Check.Visible = False
End If
End Sub
Oct 30 '06 #1
Share this Question
Share on Google+
9 Replies


NeoPa
Expert Mod 15k+
P: 31,474
Forms!frmStudentData.sfrmEntryPlacement.lblContact Check.Visible = True
If the bold lines are where your problem occurs then I think the problem is that instead of referring to the object within the subform within the form within the forms collection you need to refer to the object within the {tab of the form} within the form within the forms collection.

Another possibility is that you have a label called 'lblContact Check' (as quoted in your post) - If this is not a typo, then it needs to enclosed in [] braces. Any name with embedded spaces (inherently dodgy ;) ) must be surrounded by them so the interpreter know it's not the end of the construct.

I'm not positive about the reference using the tab name but I am about the spaces in names so check that first.

Good luck.
Oct 30 '06 #2

MMcCarthy
Expert Mod 10K+
P: 14,534
Syntax should be:


Forms![frmStudentData]![sfrmEntryPlacement].Form![lblContactCheck].Visible = True
Oct 30 '06 #3

P: 65
Yes, the bolded lines are the ones which are causing me trouble. The space was a typeo. I dont know where it came from because I copy/pasted. when i post on here without using [ ] it inserts spaces... I've tried
variations of

Expand|Select|Wrap|Line Numbers
  1. tabFE.frmStudentData.sfrmEntryPlacement.[lblContactCheck].Visible = False 
but that doesnt seem to do the trick.

Expand|Select|Wrap|Line Numbers
  1. Forms![frmStudentData].[sfrmEntryPlacement].[lblContactCheck].Visible = True
gives me "access can't find the field '|' referred to in your expression".

so to summarize again I have two objects on a tab: (1) lstPlacements and (2) sfrmEntryPlacement. I want to reference a label on sfrmEntryPlacement from the click event on lstPlacements.
Oct 30 '06 #4

P: 65
this gives me error "can't find the field sfrmEntryPlacement"

Syntax should be:


Forms![frmStudentData]![sfrmEntryPlacement].Form![lblContactCheck].Visible = True
Oct 30 '06 #5

MMcCarthy
Expert Mod 10K+
P: 14,534
this gives me error "can't find the field sfrmEntryPlacement"
sfrmEntryPlacement is the name of your subform but access also give the subform object a name.

In the main form design view click on the frame of the subform and open the properties window. Under the Other tab there is a property called name. That is what needs to be in here.
Oct 30 '06 #6

P: 65
thank you this works perfectly!

sfrmEntryPlacement is the name of your subform but access also give the subform object a name.

In the main form design view click on the frame of the subform and open the properties window. Under the Other tab there is a property called name. That is what needs to be in here.
Oct 30 '06 #7

P: 65
Sorry to bother you again but I have one more question. I now want to do the opposite and reference the listbox from the subform so that I can requery it. i have been trying

Forms!frmStudentData.lstPlacements.Requery

but that doesn't do it. Can anyone reccomend a good website or book that covers referencing? I dont really understand the syntax yet.

thanks for your time!

sfrmEntryPlacement is the name of your subform but access also give the subform object a name.

In the main form design view click on the frame of the subform and open the properties window. Under the Other tab there is a property called name. That is what needs to be in here.
Oct 31 '06 #8

MMcCarthy
Expert Mod 10K+
P: 14,534
Me.Parent.lstPlacements.Requery

The above should do it.

Anyhow the best website for this is posted below. It is the definitive answer to all reference questions on forms and subforms.

http://www.mvps.org/access/forms/frm0031.htm
Oct 31 '06 #9

P: n/a
M McCarthy - I love you! Thanks dude, couldn't see why my references to subforms weren't working. In the database window, my subform was called 'subfrmX' but in the 'other' property it was called 'subfrmY'...you're a star! (btw I'm in Dublin as well and if I ever see you, I owe you a pint)

Thanks again
Ken
Nov 16 '10 #10

Post your reply

Sign in to post your reply or Sign up for a free account.