473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Referencing a Subform

132 100+
Hello,

Trying to nail down the correct syntax to reference a subform. Here is what I have, but it's not working:

Forms![MainForm]![Actions Subform]![Action Date].SetFocus
Mar 12 '08 #1
50 4905
Scott Price
1,384 Expert 1GB
Try Forms![MainForm]![Subform].Form![ControlName]

Regards,
Scott
Mar 13 '08 #2
Proaccesspro
132 100+
Try Forms![MainForm]![Subform].Form![ControlName]

Regards,
Scott
Here is my new code:

Forms![MainForm]![Actions Subform].Form![Action Date].SetFocus

When run, I get an error stating Access can not find the field actions subform

I am trying to set focus to the field Action date on the subform Actions subform contained in the Main form.
Mar 17 '08 #3
Scott Price
1,384 Expert 1GB
Can you show us the relevant bits of code leading up to this one?

Regards,
Scott
Mar 17 '08 #4
Proaccesspro
132 100+
Can you show us the relevant bits of code leading up to this one?

Regards,
Scott
Sure............

Expand|Select|Wrap|Line Numbers
  1. Dim rs As DAO.Recordset
  2.  
  3. Set rs = CurrentDb.OpenRecordset("Case")
  4.  
  5. rs.AddNew
  6. 'rs.Update
  7.  
  8.  
  9. 'Me![qryReviewJobs SubForm]![txtJobNumber]
  10. 'Forms![mainform]![actions subform]![Action Date].SetFocus
  11. Forms("mainform")![actions subform]![Action Date]
  12. 'Form_frmFieldServiceDatabase![qryReviewJobs SubForm]![txtJobNumber]
  13.  
  14.  
  15.  
  16. 'Forms![MainForm]![Actions Subform].Form![Action Date]
  17.  
  18. 'Forms![MainForm]![Actions Subform]![Action Date].SetFocus
  19. 'Forms![MainForm]!CmbPriIsuuse.SetFocus
  20.  
  21. Exit_Command136_Click:
  22.     Exit Sub
  23.  
  24. Err_Command136_Click:
  25.     MsgBox Err.Description
  26.     Resume Exit_Command136_Click
Mar 17 '08 #5
Scott Price
1,384 Expert 1GB
Make absolutely sure that these are spelled correctly.

Second, try setting the focus to the main form before moving the focus to the subform control that you are looking for.

And, just checking, this really is a sub-form as in a separate form that you have included in the first, and not a tabbed control?

Regards,
Scott
Mar 17 '08 #6
Proaccesspro
132 100+
Make absolutely sure that these are spelled correctly.

Second, try setting the focus to the main form before moving the focus to the subform control that you are looking for.

And, just checking, this really is a sub-form as in a separate form that you have included in the first, and not a tabbed control?

Regards,
Scott
They are spelled correctly...

I set the focus to the main form...no dice!

It is a sub form...However, the main form does have 3 pages or tabs to it and the subform is on page 2 or tab 2
Mar 17 '08 #7
Stewart Ross
2,545 Expert Mod 2GB
Hi Proaccesspro. Scott has correctly posted the correct way to reference a subform control in post #2, but none of the lines in the code use this format, whether commented out or not.

If the code you posted in post #5 is what is generating the error then what you have asked and subsequently posted does not reflect the reality of your code. The only active line that isn't commented out is line 11, which is not referring to the subform control in the way you are mentioning in post #3. This line also is just a bare reference to the control - there is no assignment statement involved or other action (such as the SetFocus you have mentioned) to perform.

If you are wishing to add a new record to a recordset based on values copied from the current record in your subform you should have some idea in advance of which fields you need to assign. You do not need to physically set focus on a control to copy its value.

I would suggest that you step back a little and consider what you are trying to achieve. There is often a much simpler way to copy or append records using the query builder or an SQL statement, even from code, than by looping through recordsets or trying to access the controls on a form this way.

-Stewart
Mar 17 '08 #8
Hello,

Trying to nail down the correct syntax to reference a subform. Here is what I have, but it's not working:

Forms![MainForm]![Actions Subform]![Action Date].SetFocus

Try this method, Works very well to me Bring >> On Open Form in ( Subform )
-------------------------------
Forms!MainForm!ChildName.SetFocus
Forms!MainForm!ChildName!TextBox.SetFocus
------------------------------

Put your Childname as yours and text Box as yours

Taken from this Forum
Mar 18 '08 #9
Proaccesspro
132 100+
Hi Proaccesspro. Scott has correctly posted the correct way to reference a subform control in post #2, but none of the lines in the code use this format, whether commented out or not.

If the code you posted in post #5 is what is generating the error then what you have asked and subsequently posted does not reflect the reality of your code. The only active line that isn't commented out is line 11, which is not referring to the subform control in the way you are mentioning in post #3. This line also is just a bare reference to the control - there is no assignment statement involved or other action (such as the SetFocus you have mentioned) to perform.

If you are wishing to add a new record to a recordset based on values copied from the current record in your subform you should have some idea in advance of which fields you need to assign. You do not need to physically set focus on a control to copy its value.

I would suggest that you step back a little and consider what you are trying to achieve. There is often a much simpler way to copy or append records using the query builder or an SQL statement, even from code, than by looping through recordsets or trying to access the controls on a form this way.

-Stewart
Stewart,

Here is what I now have:

Forms![MainForm]![Actions Subform].Form! [Action Date]

The only way Access likes the code is if I have a space between Form! and [Action Date]. When I run it is still gives me this error "can't find the field '|' referred to in your experssion.

If I try to remove the space between Form! and [Action Date] is get the compile error: expected =
Mar 18 '08 #10
Scott Price
1,384 Expert 1GB
Can you give us a screen shot of the form in question?

Regards,
Scott
Mar 18 '08 #11
Stewart Ross
2,545 Expert Mod 2GB
...If I try to remove the space between Form! and [Action Date] is get the compile error: expected =
Hi Proaccesspro. The 'expected = ' compiler message is quite right - as I said in my reply you are not doing anything with or to the control. The compiler is expecting an assignment statement, or an action to be performed such as .setfocus.

Picture what you have written:

TheControl

instead of:

Something = TheControl, or
Something = TheControl.PropertyValue, or
TheControl = Something, or
TheControl.PropertyValue = Something, or
TheControl.Dosomething

No wonder the compiler objects.

As a check of your use of the correct syntax you can test your code with the (unnecessary) SetFocus which the compiler will be able to interpret. Replace the line you have quoted with

Expand|Select|Wrap|Line Numbers
  1. Forms![MainForm]![Actions Subform].Form![Action Date].Setfocus
It is meaningless to add spaces at random in an expression in the hope it will work. It will not. It just takes something which was correct and makes it randomly incorrect - please don't take this approach to testing.

I have removed the space which was in your sample in the suggestion above.

A screenshot as Scott suggested would indeed be helpful, to establish what your form's structure really is.

-Stewart
Mar 18 '08 #12
Proaccesspro
132 100+
Can you give us a screen shot of the form in question?

Regards,
Scott
How??????????????????????????????
Mar 18 '08 #13
Proaccesspro
132 100+
How??????????????????????????????
Stewart,

Thanks for the help on this....Forgot to mention in my post that in fact I tried to add the .setfocus command and it still does not work. When added, I get this error: can't fing the field actions subform

Here is the code I have:

Forms![MainForm]![Actions Subform].Form![Action Date].SetFocus
Mar 18 '08 #14
Stewart Ross
2,545 Expert Mod 2GB
... When added, I get this error: can't fing the field actions subform
Forms![MainForm]![Actions Subform].Form![Action Date].SetFocus
Hi. What this suggests is that the name of your subform control is not Actions Subform. Click on the subform and check that its Name property is indeed Actions Subform. If it is something different, then you will have to use the name that it really is in your references to it.

By the way, to check that you are referring to the correct main form you could shorten the reference using the Me property:

Me![Actions Subform].Form![Action Date].Setfocus

-Stewart
Mar 18 '08 #15
Scott Price
1,384 Expert 1GB
The reason we asked for a screen shot is that we suspect there is a problem with terminology.

The errors that you are getting are consistent with two problems: 1. A form that does NOT have a sub-form; 2. A mis-spelled reference.

We've gone through the spelling check, so we're now working on making sure you are referring to the same thing we are when we speak of a 'sub-form'. In proper terminology, a sub-form is a separate form that has been added to the second form. To test whether you really have a sub-form or not, you can remove the reference to the Action Subform.Form in your code and try it again.

You can find a freeware screen capture utility here. Just click on the link and download the program and follow the instructions to capture a screen shot of the part of the form in question. When you have captured the shot, to add it to this thread, create a reply, then within the 1 hour time limit to edit your post, click on the Edit/Delete button on the bottom of the post, and click the Manage Attachments button. Upload your screen shot and we'll take a look.

Regards,
Scott
Mar 18 '08 #16
Proaccesspro
132 100+
Hi. What this suggests is that the name of your subform control is not Actions Subform. Click on the subform and check that its Name property is indeed Actions Subform. If it is something different, then you will have to use the name that it really is in your references to it.

By the way, to check that you are referring to the correct main form you could shorten the reference using the Me property:

Me![Actions Subform].Form![Action Date].Setfocus

-Stewart
The form name is indeed Actions Subform
Mar 18 '08 #17
Proaccesspro
132 100+
The form name is indeed Actions Subform

it will not allow me to upload the bmp...says the file is to large!!!
Mar 18 '08 #18
Scott Price
1,384 Expert 1GB
How big is the bmp file?

Regards,
Scott
Mar 18 '08 #19
Proaccesspro
132 100+
How big is the bmp file?

Regards,
Scott
5 MB......................
Attached Files
File Type: zip mainform.zip (26.5 KB, 125 views)
Mar 18 '08 #20
Proaccesspro
132 100+
5 MB......................

OK, I zipped the file.....The subform is on the APPEAL INFORMATION tab...

I will upload a snapshot of that also
Mar 18 '08 #21
Proaccesspro
132 100+
OK, I zipped the file.....The subform is on the APPEAL INFORMATION tab...

I will upload a snapshot of that also

I think a light bulb just went on!! I just realized the text box I am trying to set focus to is actually located on a third form...I have the main form, then the actions subform, and then a case subform.....SO, I have 2 subforms contained on 1 form....How would I reference the nested forms???
Mar 18 '08 #22
Scott Price
1,384 Expert 1GB
In the attachment you sent, the Patient Information tab doesn't show a sub-form at all! Does this screen shot accurately reflect what you are trying to reference through code?

If you want to refer to a text box/ combo box, etc control on the tab control, the reference is made without any mention of sub-forms:
Expand|Select|Wrap|Line Numbers
  1. Forms![MainForm]![ControlName].SetFocus.
If you have a second form that is popping up separately from this main form, it is referred to as a form in it's own right:
Expand|Select|Wrap|Line Numbers
  1. Forms![ActionSubForm]![ControlName].SetFocus
Regards,
Scott
Mar 18 '08 #23
Scott Price
1,384 Expert 1GB
You posted while I was replying, sorry :-)

Yes, please attach a similar file with the screenshot of the Appeals tab! The other doesn't do us too much good at this point.

Regards,
Scott
Mar 18 '08 #24
NeoPa
32,556 Expert Mod 16PB
A link that may help (Referring to Items on a Sub-Form).
Mar 18 '08 #25
NeoPa
32,556 Expert Mod 16PB
FYI. Capturing a screenshot can also be done (to the clipboard) with the PrtScr key. Alt-PrtScr captures just the current application window.
Mar 18 '08 #26
Stewart Ross
2,545 Expert Mod 2GB
In the attachment you sent, the Patient Information tab doesn't show a sub-form at all! Does this screen shot accurately reflect what you are trying to reference through code?
Absolutely spot-on, Scott. Proaccesspro, when you say subforms do you mean the pages in the tab control? These are not subforms at all... Terminology is everything here; a subform is a distinctly different object from a tabbed control. We can only go on what we are told by you in your posts.

-Stewart
Mar 18 '08 #27
Proaccesspro
132 100+
You posted while I was replying, sorry :-)

Yes, please attach a similar file with the screenshot of the Appeals tab! The other doesn't do us too much good at this point.

Regards,
Scott
Will do....................
Attached Files
File Type: zip mainform.zip (41.4 KB, 93 views)
Mar 18 '08 #28
Proaccesspro
132 100+
Will do....................

I uploaded the form...This shows the second tab on the main form...As you can see, there are 2 additional forms on this tab...I need to set focus to a text box on the 3rd form (one on the bottom that is just visable)
Mar 18 '08 #29
Proaccesspro
132 100+
Absolutely spot-on, Scott. Proaccesspro, when you say subforms do you mean the pages in the tab control? These are not subforms at all... Terminology is everything here; a subform is a distinctly different object from a tabbed control. We can only go on what we are told by you in your posts.

-Stewart
Stewart,

I have subforms within each of the different tab controls. Hope this makes sence.
Mar 18 '08 #30
Scott Price
1,384 Expert 1GB
After looking at the second attachment, it starts to make more sense now :-)

You have a nested sub-form within a sub-form.

The way to reference this is just a continuation of the reference for a single subform...

Expand|Select|Wrap|Line Numbers
  1. Forms![Form1Name]![SubformName].Form![Subform2Name].Form![ControlName]
Regards,
Scott
Mar 18 '08 #31
Scott Price
1,384 Expert 1GB
Another option which reduces your possibility of mis-referencing the sub-form in question is to set its Has Module property to Yes. Then you can do away with the leading Forms![MainForm]![Subform1] etc reference and simply refer to the form like this:

Expand|Select|Wrap|Line Numbers
  1. Form_[Subform2Name].[ControlName]
.

I just tested this in my test database and it works as advertised :-)

Regards,
Scott
Mar 18 '08 #32
Proaccesspro
132 100+
After looking at the second attachment, it starts to make more sense now :-)

You have a nested sub-form within a sub-form.

The way to reference this is just a continuation of the reference for a single subform...

Expand|Select|Wrap|Line Numbers
  1. Forms![Form1Name]![SubformName].Form![Subform2Name].Form![ControlName]
Regards,
Scott
Scott,

Well were getting closer but I STILL can't get it to work....Here is what I have:

Forms![MainForm]![Case subform].Form![Actions Subform].Form![Action Date].SetFocus

Does it make any difference that the Actions Subforms' default view is datasheet?
Mar 18 '08 #33
Scott Price
1,384 Expert 1GB
It's actually working, just not perhaps in the way you want it to!

Testing in my test db, I've proven that the focus is set as required. You can do this by setting a String variable to the .Text property of the text box in question. Then doing a Debug.Print [stringvariable] method. When called without first setting the focus, it throws an error, as the .Text property is only available when a text box has the focus.

However, it didn't result in a blinking cursor in the text box ready to receive user input! I'm assuming this is what you are after?

Regards,
Scott
Mar 18 '08 #34
Proaccesspro
132 100+
It's actually working, just not perhaps in the way you want it to!

Testing in my test db, I've proven that the focus is set as required. You can do this by setting a String variable to the .Text property of the text box in question. Then doing a Debug.Print [stringvariable] method. When called without first setting the focus, it throws an error, as the .Text property is only available when a text box has the focus.

However, it didn't result in a blinking cursor in the text box ready to receive user input! I'm assuming this is what you are after?

Regards,
Scott
"However, it didn't result in a blinking cursor in the text box ready to receive user input! I'm assuming this is what you are after?" ---- > Y E S!!!

Also, when I run the code, the compiler blows up at said line and gives me this error: "can't find the field Actions Subform"
Mar 18 '08 #35
Scott Price
1,384 Expert 1GB
To get the cursor set in the select control you need to do two more steps:

Set the focus to the first subform first, then in the next line of code set it to the second subform, finally set the focus to the control located on the nested subform!
Expand|Select|Wrap|Line Numbers
  1. Forms![MainForm]![Subform1Name].SetFocus
  2. Forms![MainForm]![Subform1Name].Form![Subform2Name].SetFocus
  3. Forms![MainForm]![Subform1Name].Form![Subform2Name].Form![ControlName].SetFocus
Just tested this as well and it worked in my test db.

This MS Knowledge Base article covers the necessary information.

Regards,
Scott
Mar 18 '08 #36
Proaccesspro
132 100+
To get the cursor set in the select control you need to do two more steps:

Set the focus to the first subform first, then in the next line of code set it to the second subform, finally set the focus to the control located on the nested subform!
Expand|Select|Wrap|Line Numbers
  1. Forms![MainForm]![Subform1Name].SetFocus
  2. Forms![MainForm]![Subform1Name].Form![Subform2Name].SetFocus
  3. Forms![MainForm]![Subform1Name].Form![Subform2Name].Form![ControlName].SetFocus
Just tested this as well and it worked in my test db.

This MS Knowledge Base article covers the necessary information.

Regards,
Scott

Scott,

It still blows on lime 2...Keeps telling me it cant find the field Actions Subform
Expand|Select|Wrap|Line Numbers
  1. Forms![MainForm]![Case subform].SetFocus
  2. Forms![MainForm]![Case subform].Form![Actions Subform].SetFocus
  3. Forms![MainForm]![Case subform].Form![Actions Subform].Form![Action Date].SetFocus
It does set the focus to the Case subform on tab 2.
Mar 18 '08 #37
Scott Price
1,384 Expert 1GB
Does this db have sensitive information in it or can you send me a sanitized copy to take a look at it?

Post back here and I'll enable the 'Send Email' button in my profile if you wish to take this route. Also, please zip the db if you choose to send it to me.

Regards,
Scott
Mar 18 '08 #38
Proaccesspro
132 100+
Does this db have sensitive information in it or can you send me a sanitized copy to take a look at it?

Post back here and I'll enable the 'Send Email' button in my profile if you wish to take this route. Also, please zip the db if you choose to send it to me.

Regards,
Scott

I can send you a sanitized version...
Mar 18 '08 #39
Scott Price
1,384 Expert 1GB
Go ahead and click on my profile, then send the zipped db to me.

Regards,
Scott
Mar 18 '08 #40
Proaccesspro
132 100+
Go ahead and click on my profile, then send the zipped db to me.

Regards,
Scott

I'm using version 2000....is that a problem??
Mar 18 '08 #41
Scott Price
1,384 Expert 1GB
Shouldn't be. I'm using A2003, which maintains the ability to open and work with the A2000 file formats without affecting their compatibility. I'll make the corrections and send it back to you!

Regards,
Scott
Mar 18 '08 #42
Proaccesspro
132 100+
Shouldn't be. I'm using A2003, which maintains the ability to open and work with the A2000 file formats without affecting their compatibility. I'll make the corrections and send it back to you!

Regards,
Scott
Scratch that...it's 2002
Mar 18 '08 #43
Proaccesspro
132 100+
Does this db have sensitive information in it or can you send me a sanitized copy to take a look at it?

Post back here and I'll enable the 'Send Email' button in my profile if you wish to take this route. Also, please zip the db if you choose to send it to me.

Regards,
Scott
Scott,

Tried to send the email, but it is not enabled....
Mar 19 '08 #44
Scott Price
1,384 Expert 1GB
Try again. If it still doesn't work, download the vCard with my email address on it.

If that still doesn't work, attach the zipped database to this thread.

Regards,
Scott
Mar 19 '08 #45
How I seen in the Atachments it is two childs inside same form with Tabs adapted

I tried one solution and worked well..


1.MAIN FORM on Tab_Click set >> Me.ChildName.Setfocus
2.Second Form - On Load set >> Me.ChildName.Setfocus
3.Third Form - On Load set >> Me.TextName.Setfocus

ChildName and TextName bring what Yours are.
and Tab Name As Yours
Those condittion bring focus in the Text Box Of Third Loaded form.

Regards


Attachment deleted, as per warning posted.
Mar 19 '08 #46
Scott Price
1,384 Expert 1GB
Ragazzo,

Your example has very little value since you disabled all menu items, and blocked access to the code of your database sample.

I have deleted the attachment since there is no way of verifying whether you have included possibly malicious code.

MODERATOR
Mar 19 '08 #47
Sorry for that...

Aplication was dedicated for something else i just adapted for purpose of what

it`s asked in this topic and forgot to prepare everything for simple use...

I am sorry for this and I post again after I have make it very simple.


Regards
Ragazzo
Attached Files
File Type: zip TestTab.zip (31.6 KB, 107 views)
Mar 19 '08 #48
Proaccesspro
132 100+
Scott,

I sent the DB to you.......
Mar 19 '08 #49
Proaccesspro
132 100+
Scott,

I sent the DB to you.......
The "Has Multiple Appeal" button on the MAIN form contains the code in question
Mar 19 '08 #50

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

Similar topics

2
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a main form with a continuous subform. On the main form I have a text box that references a field on the subform. What I'd like it to do is show the value...
3
by: shumaker | last post by:
This code from the subform works for getting the value of a field of the main form named "WorkSheet": MsgBox Form_WorkSheet.Recordset.Fields("Clerk").Value Each record in the mainform datasheet...
2
by: Axel | last post by:
Hi, a question about something that seems very simple at first glance: is it possible to reference other controls of a subform in a query window without referencing through the parent form? I...
9
by: Alan | last post by:
Hmmm, I'm not too good with the syntax of referencing a subreport. I have frmInvoice which has the invoice details (e.g. ProductCode, ProductCost etc) in the subform frmInvoiceDetails. I'm trying...
21
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.