I am trying to open Sub Form using the command below, but i am getting error.
Please confirm if i can open sub form using this command:
Call DoCmd.OpenForm("Forms![main_form]![sub_form]", acNormal, , , , acWindowNormal)
22 17215
A subform would normally open automatically when the main form it's part of opens. If you're trying to independantly open a form that is normally used as a subform, you simply open it as you would any other form, with no reference to it being a "sub" form.
A subform would normally open automatically when the main form it's part of opens. If you're trying to independantly open a form that is normally used as a subform, you simply open it as you would any other form, with no reference to it being a "sub" form.
I am opening the main form, which has a subform in it as well. I know you are saying when i open the main form, the subform gets opened as well.
But unless i open the subform explicity like this: - 'Call DoCmd.OpenForm("sub_search_form", acNormal, , , , acWindowNormal)
The following piece of code will be higlighted and error will appear : - Dim formSub As Form
-
Set formSub = Forms.Item("sub_search_form")
The error is: 2450 - Cant find the form
sub_search_form
But when i open it explicity as i mentioned above, no problem happens
I am opening the main form similar way as above
Any idea whats wrong
How would you open a subform only. This subform is on a mainform but i want to open the subform only , not the whole form.
how would i do that
I have tried with this: - Call DoCmd.OpenForm (" Forms![main_form] ! [sub_form] ")
but this gives me error: not found...
help?
NeoPa 32,556
Expert Mod 16PB
As a full member now, you should know that we expect your code to be posted in [code] tags (See How to Ask a Question).
This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.
Please use the tags in future.
MODERATOR.
NeoPa 32,556
Expert Mod 16PB
Apart from the CODE tags, your question is impossible to answer as you don't give us the information we need. It's not the Experts job to get that information from you. If you want help, go to the trouble yourself of posting a question that makes sense.
I need to open subform only because i need to do some ADO operations with it , not because i want to show it on screen.
If i open the main form, which has subform on it. I know you are saying by opening the main form, the subform gets opened as well. But if i open the main form, i cant do any ADO works with the subform.
For example:
I open main form: -
Call DoCmd.OpenForm("main_form", acNormal, , , , acWindowNormal)
-
-
I want to use the code below for subform:
-
Set formSub = Forms.Item("sub_form")
-
formSub.RecordSource = sqlQry
-
To do this, i have to open the subform physically with DoCmd.OpenForm.
Now when i want to close the mainform, i will have to close the subform as well seperately -- Then whats the purpose of having a subform on a mainform!
Thats why i want a way by which i open the mainform, by which its subform gets opened as well for any DAO, etc operations. And when i close the mainfom, i dont need to explicity close the subform.
Apart from the CODE tags, your question is impossible to answer as you don't give us the information we need. It's not the Experts job to get that information from you. If you want help, go to the trouble yourself of posting a question that makes sense.
Is it possible to do the following without opening the form : -
Dim subForm As Form
-
Set subForm = Forms.Item("sub_form_client")
-
subForm.RecordSource = sqlQry
-
If the form is not opened, then i get run-time error - form not found !
Just add the subfrom to your mainform in design mode. When you explicitly open the form in your code then. You get the form 2 times. Once in your main form, and once as a main form. The second one is the one you don't want because you have to close it by hand each time.
So normally you should be able to see the subform on you main form if you added it correctly. When you don't want to see it you can set the property visibly of the subfotm to false.
Ps. Are you useing DAO or ADO because they have their differences...
Ok, so far so good
If i open the subform on its own. it seems to work i.e show updated results, etc
But when i open the main form, which has the subform on it, there it doesn't show the updated results..
any idea why is that?
Just add the subfrom to your mainform in design mode. When you explicitly open the form in your code then. You get the form 2 times. Once in your main form, and once as a main form. The second one is the one you don't want because you have to close it by hand each time.
So normally you should be able to see the subform on you main form if you added it correctly. When you don't want to see it you can set the property visibly of the subfotm to false.
Ps. Are you useing DAO or ADO because they have their differences...
Try to adjust your recordsource and filter. It is possible the error is situated there. I had to search for the correct filter for about 2 hours this morning.
Also you might want to link your mainform and your subform trough an ID. That way they know af each other and know what to display. It is a property of the subform. In dutch: "Subvelden koppelen" and "Hoofdvelden koppelen". Literally translated: Link subfields and Link mainfields. Working in a dutch environment zo I don't know what it is in English.
Greetz
Is it possible to do the following without opening the form : -
Dim subForm As Form
-
Set subForm = Forms.Item("sub_form_client")
-
subForm.RecordSource = sqlQry
-
If the form is not opened, then i get run-time error - form not found !
Basically no, but why would you want to ?
MTB
Tried best, but no sucess
I need to do the following: -
-
sqlQry = "SELECT name, age FROM table1"
-
Forms![client_search].Form.RecordSource = sqlQry
-
When i do it on the actual form, it works but when that form is on another form as a subform it doesn't work (i mean it does get updated)
client_search form is a "Continous Form"
can i do this kind of stuff on a form when its a subform - i wonder?
Try to adjust your recordsource and filter. It is possible the error is situated there. I had to search for the correct filter for about 2 hours this morning.
Also you might want to link your mainform and your subform trough an ID. That way they know af each other and know what to display. It is a property of the subform. In dutch: "Subvelden koppelen" and "Hoofdvelden koppelen". Literally translated: Link subfields and Link mainfields. Working in a dutch environment zo I don't know what it is in English.
Greetz
I've merged these two posts together, questionit, since you're asking the same identical question again! I would suggest, as NeoPa has already suggested, that your read (or re-read) How to Ask a Question paying particular attention to the section on Double Posting.
Linq
Tried best, but no sucess
I need to do the following: -
-
sqlQry = "SELECT name, age FROM table1"
-
Forms![client_search].Form.RecordSource = sqlQry
-
When i do it on the actual form, it works but when that form is on another form as a subform it doesn't work (i mean it does get updated)
client_search form is a "Continous Form"
can i do this kind of stuff on a form when its a subform - i wonder?
Hi!
Form opened as subform does not exist in Forms collection. You may reference subform Form object the following way: - Forms![MainForm]![SubForm].Form
But be sure the subform was really opened (Access will open it when it will need to display it). E.g. if a main form is in datasheet view, then its subform will not be loaded until the datasheet was not expanded and any VBA referencing to it will cause an error.
Hi FishVal
What you mean by 'datasheet not Expanded' ? By the way, mymain form is 'Single form
As you have said way to open the subform, when i do the following, i get wrror, - form doesn't exist - can you check if this is correct: -
Call DoCmd.OpenForm("Forms![client_form_main]![client_form_sub].Form", acNormal, , , , acWindowNormal)
-
-
Hi!
Form opened as subform does not exist in Forms collection. You may reference subform Form object the following way: - Forms![MainForm]![SubForm].Form
But be sure the subform was really opened (Access will open it when it will need to display it). E.g. if a main form is in datasheet view, then its subform will not be loaded until the datasheet was not expanded and any VBA referencing to it will cause an error.
FishVal said that - Forms![MainForm]![SubForm].Form
was the way to reference the subform, he didn't say it was the way to open the subform! He told you, as I have previously, that the subform is opened when the parent form is opened. The problem, I think, is that you're trying to open the form Forms![client_form_main]![client_form_sub].Form and this is not a form! It's an object (control) on the form client_form_main, but it's not a form! You can't open it anymore than you could open a textbox or a command buttton.
Linq ;0)>
Hi FishVal
What you mean by 'datasheet not Expanded' ? By the way, mymain form is 'Single form
As you have said way to open the subform, when i do the following, i get wrror, - form doesn't exist - can you check if this is correct: -
Call DoCmd.OpenForm("Forms![client_form_main]![client_form_sub].Form", acNormal, , , , acWindowNormal)
-
-
1. As soon as your main form is in Single form view you'll never deal with "subform late opening". Plz don't mention this.
2. I've said this is the way to get a Form object of subform opened on a main form, which will be done automatically as soon as you have placed subform control to the main form. -
Dim frmSubForm As Form
-
Set frmSubForm = Forms![client_form_main]![client_form_sub].Form
-
frmSubForm.RecordSource = "...."
or simply - Forms![client_form_main]![client_form_sub].Form.RecordSource = "...."
or in the mainform module - Me![client_form_sub].Form.RecordSource = "...."
Summarizing all above:
1. If you open subform as a separate form with DoCmd.OpenForm, then Forms![client_form_sub] will return you Form object.
2. If subform is a control on the main form (usual situation), then it will be opened automatically and Forms![client_form_main]![client_form_sub].Form will return you Form object.
The problem, I think, is that you're trying to open the form Forms![client_form_main]![client_form_sub].Form and this is not a form! It's an object (control) on the form client_form_main, but it's not a form! You can't open it anymore than you could open a textbox or a command buttton.
Linq ;0)>
Hi, Linq.
You are somewhat confused, I suppose.
Forms![client_form_main]![client_form_sub] will return control
Forms![client_form_main]![client_form_sub].Form will return form
It could be easily checked in VBA Intermediate using TypeName function (BTW very useful one)
? TypeName(Forms![client_form_main]![client_form_sub])
SubForm
? TypeName(Forms![client_form_main]![client_form_sub].Form)
Form_client_form_sub
The latter is name of class created by Access for this particulary form, it provides all form properties needed.
Hi FishVal
I have got everything working now with your help
Thanks a lot for your help.
Hi, Linq.
You are somewhat confused, I suppose.
Forms![client_form_main]![client_form_sub] will return control
Forms![client_form_main]![client_form_sub].Form will return form
It could be easily checked in VBA Intermediate using TypeName function (BTW very useful one)
? TypeName(Forms![client_form_main]![client_form_sub])
SubForm
? TypeName(Forms![client_form_main]![client_form_sub].Form)
Form_client_form_sub
The latter is name of class created by Access for this particulary form, it provides all form properties needed.
Hi FishVal
I have got everything working now with your help
Thanks a lot for your help.
You are welcome. Glad my advice was helpful.
Hi fishVal,
Can you give me some other good functions like TypeName to use in Immediate window
Thanks
Hi, Linq.
You are somewhat confused, I suppose.
Forms![client_form_main]![client_form_sub] will return control
Forms![client_form_main]![client_form_sub].Form will return form
It could be easily checked in VBA Intermediate using TypeName function (BTW very useful one)
? TypeName(Forms![client_form_main]![client_form_sub])
SubForm
? TypeName(Forms![client_form_main]![client_form_sub].Form)
Form_client_form_sub
The latter is name of class created by Access for this particulary form, it provides all form properties needed.
Hi fishVal,
Can you give me some other good functions like TypeName to use in Immediate window
Thanks
Hi, there.
You can use any VBA function or/and object property/method in Immediate window, don't know which ones are generally better than others. :)
BTW what concerns TypeName function, I particury prefer to use it to quickly see a type of some deeply nested object property, in generally Watch window is more suitable to inspect regular and object variables during code tracing.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Konstantin |
last post by:
Can someone help me figure out a way to open a form only once in an MDI app.
I have an MDI app that contains several forms. I use each form depending on
the type of document that the user needs...
|
by: Julia Baresch |
last post by:
Hi everyone,
As some of you may know, we've been having trouble with an
unrecognized database format error.
Today I installed an unfinished project on the workstation of one of
my users. ...
|
by: petersk |
last post by:
Firstly I am an older person trying to teach myself to create a project
and teach myself Access VBA programming along the way.
I anticipate a number of problems I will need help with but here...
|
by: Simon Abolnar |
last post by:
I would like to know how to open child form from dialog form.
Thanks for help!
Simon
|
by: rdemyan via AccessMonster.com |
last post by:
My application is split into a front end and back end. Each user has their
own copy of the front end.
There are a few forms I only want to be open for one user at a time. So I've
implemented the...
|
by: Academic |
last post by:
I have a MDI form, sometimes child forms and sometimes forms that are
neither
If I close the app the child forms closing and closed event happens followed
by the Mdi form receiving the...
|
by: Bob Alston |
last post by:
Looking for someone with experience building apps with multiple
instances of forms open. I am building an app for a nonprofit
organizations case workers. They provide services to the elderly.
...
|
by: waynetheengineer |
last post by:
Hi,
I'm trying to write code for a form when it closes. It's supposed to requery a combo box depending on which form is currenlty open in the background behind the current form, shown below:
...
|
by: =?Utf-8?B?R3JlZw==?= |
last post by:
How can I tell via code if a Form is already open.
Each time my forms load I have some initialization code that runs, but if
the form is already open and hidden I don't want that initialization...
|
by: billa856 |
last post by:
Hi,
My project is in MS Access 2002.
In that I want to open one form multiple times.
I put one button on my main form.
Now whenever I click on that button than form will be open.
Now when I...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
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...
| |