473,383 Members | 1,880 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,383 software developers and data experts.

how to open Sub form

553 512MB
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)
Jul 21 '07 #1
22 17215
missinglinq
3,532 Expert 2GB
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.
Jul 21 '07 #2
questionit
553 512MB
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:
Expand|Select|Wrap|Line Numbers
  1. 'Call DoCmd.OpenForm("sub_search_form", acNormal, , , , acWindowNormal)
The following piece of code will be higlighted and error will appear :

Expand|Select|Wrap|Line Numbers
  1.  Dim formSub As Form
  2.            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
Jul 21 '07 #3
questionit
553 512MB
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:
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.OpenForm (" Forms![main_form] ! [sub_form] ")
but this gives me error: not found...


help?
Jul 21 '07 #4
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.
Jul 22 '07 #5
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.
Jul 22 '07 #6
questionit
553 512MB
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:

Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.OpenForm("main_form", acNormal, , , , acWindowNormal)
  2.  
Expand|Select|Wrap|Line Numbers
  1. I want to use the code below for subform:
  2.  Set formSub = Forms.Item("sub_form")
  3.    formSub.RecordSource = sqlQry
  4.  
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.
Jul 23 '07 #7
questionit
553 512MB
Is it possible to do the following without opening the form :

Expand|Select|Wrap|Line Numbers
  1. Dim subForm As Form
  2.            Set subForm = Forms.Item("sub_form_client")
  3.            subForm.RecordSource = sqlQry
  4.  
If the form is not opened, then i get run-time error - form not found !
Jul 23 '07 #8
Twanne
65
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...
Jul 23 '07 #9
questionit
553 512MB
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...
Jul 23 '07 #10
Twanne
65
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
Jul 23 '07 #11
MikeTheBike
639 Expert 512MB
Is it possible to do the following without opening the form :

Expand|Select|Wrap|Line Numbers
  1. Dim subForm As Form
  2.            Set subForm = Forms.Item("sub_form_client")
  3.            subForm.RecordSource = sqlQry
  4.  
If the form is not opened, then i get run-time error - form not found !
Basically no, but why would you want to ?

MTB
Jul 23 '07 #12
questionit
553 512MB
Tried best, but no sucess
I need to do the following:

Expand|Select|Wrap|Line Numbers
  1.  
  2.   sqlQry = "SELECT name, age FROM table1"
  3.           Forms![client_search].Form.RecordSource = sqlQry
  4.  
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
Jul 23 '07 #13
missinglinq
3,532 Expert 2GB
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
Jul 23 '07 #14
FishVal
2,653 Expert 2GB
Tried best, but no sucess
I need to do the following:

Expand|Select|Wrap|Line Numbers
  1.  
  2.   sqlQry = "SELECT name, age FROM table1"
  3.           Forms![client_search].Form.RecordSource = sqlQry
  4.  
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:
Expand|Select|Wrap|Line Numbers
  1. 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.
Jul 23 '07 #15
questionit
553 512MB
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:

Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.OpenForm("Forms![client_form_main]![client_form_sub].Form", acNormal, , , , acWindowNormal)
  2.  
  3.  
Hi!

Form opened as subform does not exist in Forms collection. You may reference subform Form object the following way:
Expand|Select|Wrap|Line Numbers
  1. 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.
Jul 23 '07 #16
missinglinq
3,532 Expert 2GB
FishVal said that
Expand|Select|Wrap|Line Numbers
  1. 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)>
Jul 23 '07 #17
FishVal
2,653 Expert 2GB
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:

Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.OpenForm("Forms![client_form_main]![client_form_sub].Form", acNormal, , , , acWindowNormal)
  2.  
  3.  
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.
Expand|Select|Wrap|Line Numbers
  1. Dim frmSubForm As Form
  2. Set frmSubForm = Forms![client_form_main]![client_form_sub].Form
  3. frmSubForm.RecordSource = "...." 
or simply
Expand|Select|Wrap|Line Numbers
  1. Forms![client_form_main]![client_form_sub].Form.RecordSource = "...." 
or in the mainform module
Expand|Select|Wrap|Line Numbers
  1. 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.
Jul 23 '07 #18
FishVal
2,653 Expert 2GB
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.
Jul 23 '07 #19
questionit
553 512MB
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.
Jul 23 '07 #20
FishVal
2,653 Expert 2GB
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.
Jul 23 '07 #21
questionit
553 512MB
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.
Jul 25 '07 #22
FishVal
2,653 Expert 2GB
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.
Jul 25 '07 #23

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

Similar topics

1
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...
2
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. ...
1
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...
14
by: Simon Abolnar | last post by:
I would like to know how to open child form from dialog form. Thanks for help! Simon
3
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...
13
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...
6
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. ...
10
waynetheengineer
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: ...
19
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...
5
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...
1
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...
0
isladogs
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...
0
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...
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...

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.