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
50 4905
Try Forms![MainForm]![Subform].Form![ControlName]
Regards,
Scott
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.
Can you show us the relevant bits of code leading up to this one?
Regards,
Scott
Can you show us the relevant bits of code leading up to this one?
Regards,
Scott
Sure............ - Dim rs As DAO.Recordset
-
-
Set rs = CurrentDb.OpenRecordset("Case")
-
-
rs.AddNew
-
'rs.Update
-
-
-
'Me![qryReviewJobs SubForm]![txtJobNumber]
-
'Forms![mainform]![actions subform]![Action Date].SetFocus
-
Forms("mainform")![actions subform]![Action Date]
-
'Form_frmFieldServiceDatabase![qryReviewJobs SubForm]![txtJobNumber]
-
-
-
-
'Forms![MainForm]![Actions Subform].Form![Action Date]
-
-
'Forms![MainForm]![Actions Subform]![Action Date].SetFocus
-
'Forms![MainForm]!CmbPriIsuuse.SetFocus
-
-
Exit_Command136_Click:
-
Exit Sub
-
-
Err_Command136_Click:
-
MsgBox Err.Description
-
Resume Exit_Command136_Click
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
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
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
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
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 =
Can you give us a screen shot of the form in question?
Regards,
Scott
...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 - 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
Can you give us a screen shot of the form in question?
Regards,
Scott
How??????????????????????????????
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
... 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
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
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
The form name is indeed Actions Subform
it will not allow me to upload the bmp...says the file is to large!!!
How big is the bmp file?
Regards,
Scott
How big is the bmp file?
Regards,
Scott
5 MB......................
5 MB......................
OK, I zipped the file.....The subform is on the APPEAL INFORMATION tab...
I will upload a snapshot of that also
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???
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: - 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: - Forms![ActionSubForm]![ControlName].SetFocus
Regards,
Scott
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
NeoPa 32,556
Expert Mod 16PB 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.
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
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....................
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)
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.
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... - Forms![Form1Name]![SubformName].Form![Subform2Name].Form![ControlName]
Regards,
Scott
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: - Form_[Subform2Name].[ControlName]
.
I just tested this in my test database and it works as advertised :-)
Regards,
Scott
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... - 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?
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
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"
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! -
Forms![MainForm]![Subform1Name].SetFocus
-
Forms![MainForm]![Subform1Name].Form![Subform2Name].SetFocus
-
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
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! -
Forms![MainForm]![Subform1Name].SetFocus
-
Forms![MainForm]![Subform1Name].Form![Subform2Name].SetFocus
-
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 - Forms![MainForm]![Case subform].SetFocus
-
Forms![MainForm]![Case subform].Form![Actions Subform].SetFocus
-
Forms![MainForm]![Case subform].Form![Actions Subform].Form![Action Date].SetFocus
It does set the focus to the Case subform on tab 2.
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
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...
Go ahead and click on my profile, then send the zipped db to me.
Regards,
Scott
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??
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
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
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....
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
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.
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
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
Scott,
I sent the DB to you.......
Scott,
I sent the DB to you.......
The "Has Multiple Appeal" button on the MAIN form contains the code in question
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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,...
|
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...
| |