Solved calling the value of a field from a main form -> subform into a query (1 Viewer)

VasiuF

Member
Local time
Today, 20:26
Joined
Apr 1, 2020
Messages
42
Hi all,
I have a problem that I can not find a solution:
form "start_meniu" - the main form, the "Note1" form, which I call in the main form.
in the form "Notes" I also have a subform that calls a parameterized query. It should receive a value of the "Note1" form in the "m_anstudiu" field.
But at the time of initialization I do not find the field m_anstudiu "of the form" Note1 "(problem I think is the addressing mode).
If I call the simple "Note1" form without including it in the main form it works ok.
Can you help me ?
Thank you
 
Last edited:

strive4peace

AWF VIP
Local time
Today, 12:26
Joined
Apr 3, 2020
Messages
1,003
hi Florin,

to reference a control in a subform that is on a mainform, use this syntax:

Code:
forms!mainform_name!subform_controlname.form.controlname

WHERE
mainform_name is the name of the form as displayed in the Navigation Pane
subform_controlname is the Name property of the subform control on the Property Sheet
controlname is the Name property of the control on the Property Sheet in the subform you want to return the value for
 
Last edited:

strive4peace

AWF VIP
Local time
Today, 12:26
Joined
Apr 3, 2020
Messages
1,003
I'm guessing that this would be:

forms!start_meniu!Note1.form.m_anstudiu ASSUMING that the subform control NAME property is Note1
 

VasiuF

Member
Local time
Today, 20:26
Joined
Apr 1, 2020
Messages
42
hi Florin,

to reference a control in a subform that is on a mainform, use this syntax:

Code:
forms!mainform_name!subform_controlname.form.controlname

WHERE
mainform_name is the name of the form as displayed in the Navigation Pane
subform_controlname is the Name property of the subform control on the Property Sheet
controlname is the Name property of the control on the Property Sheet in the subform you want to return the value for

it doesn't seem to work :(
I specify that form "note1" I renamed in "note"

View attachment 80561
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:26
Joined
Sep 21, 2011
Messages
14,226
Is this a case of subform loading before mainform?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:26
Joined
May 7, 2009
Messages
19,231
the question is "where" are you calling this query?
if in the subform, it is too early as subform Note might not be Loaded yet.

//edit: see gasmans respose
 

VasiuF

Member
Local time
Today, 20:26
Joined
Apr 1, 2020
Messages
42
the question is "where" are you calling this query?
if in the subform, it is too early as subform Note might not be Loaded yet.

//edit: see gasmans respose

and then how could I solve the problem?
query I call it in load event "note" subform
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:26
Joined
May 7, 2009
Messages
19,231
how do you call it then from "note" subform?
better create a Timer Event sub on "note" subform, then call it there.
this will ensure that subform "note" is already loaded and its control populated.
 

VasiuF

Member
Local time
Today, 20:26
Joined
Apr 1, 2020
Messages
42
and then how could I solve the problem?
query I call it in load event "note" subform

more precisely at load event form "notes" and then for filtering information, in the "lost focus" event of the "m_anstudiu" field
 

strive4peace

AWF VIP
Local time
Today, 12:26
Joined
Apr 3, 2020
Messages
1,003
hi Florin,

the form must be open in Form View when the query is run. In case that control doesn't have a value, wrap the reference with NZ (null to zero)

Code:
Nz( [Forms]![myMainFormName]![mySubform_controlName].[Form]![controlName] )

NOTE:
mySubform_controlName is the NAME PROPERTY of the subform control, not the name of the form in the Navigation Pane. To make it easier, I like to name the subform control the same name that is is called. To show the Property Sheet, press Alt-Enter
Likewise, controlName is the Name property of the control, not the field that it contains. Again, I like to make these match.

that said ... instead of putting criteria in the query, it would be better to set LinkMasterFields and LinkChildFields for the subform control holding the query!

If you don't know how to do this, please post your database with just sample records in each table if your information is sensitive.
 

strive4peace

AWF VIP
Local time
Today, 12:26
Joined
Apr 3, 2020
Messages
1,003
hi Florin,

I have your database open. Since its is in another language, please tell me what to click and pick and type. Thank you!

I used admin
 

strive4peace

AWF VIP
Local time
Today, 12:26
Joined
Apr 3, 2020
Messages
1,003
Florin , the Name property of the subform control is frmDetaliu (different than what is in it -- best, in my opinion, to eb the same)
The SourceObject is _frmArma

There is nothing in LinkMasterFields and LinkChildFields -- this is the preferable way to link information

subform_propertySheet.png


It is not a good idea to start an object name with anything except a letter, so the first character being _ could create issues ...
 

VasiuF

Member
Local time
Today, 20:26
Joined
Apr 1, 2020
Messages
42
hi Florin,

I have your database open. Since its is in another language, please tell me what to click and pick and type. Thank you!

I used admin

should be clicked on the "" Actualizare Note " button
then - Matricol - must be entered (118215) - a student will be selected
after which I should enter the study year (may be 1.2 or 3)
in the subform I must display the subjects related to the year the study is introduced
 

VasiuF

Member
Local time
Today, 20:26
Joined
Apr 1, 2020
Messages
42
Florin , the Name property of the subform control is frmDetaliu (different than what is in it -- best, in my opinion, to eb the same)
The SourceObject is _frmArma

There is nothing in LinkMasterFields and LinkChildFields -- this is the preferable way to link information

View attachment 80604

It is not a good idea to start an object name with anything except a letter, so the first character being _ could create issues ...
 

Attachments

  • select note button.png
    select note button.png
    43.8 KB · Views: 90

strive4peace

AWF VIP
Local time
Today, 12:26
Joined
Apr 3, 2020
Messages
1,003
thanks. I see other problems before I can test that. first, the database doesn't compile. I'm going to comment lines until it does.
 

VasiuF

Member
Local time
Today, 20:26
Joined
Apr 1, 2020
Messages
42
The source for frmDetaliu is selected from the right buttons, the default is _frmArma
 

strive4peace

AWF VIP
Local time
Today, 12:26
Joined
Apr 3, 2020
Messages
1,003
~~~~~~~~~ Compile ~~~~~~~~~

Whenever you change code, references, or switch versions or operating environment, or modify objects with code behind them, you should always compile and save before executing any code.

from the menu in a VBE (module) window: Debug, Compile [the name of your project]
(Alt-F11 to switch to the code window)

Fix any errors on the highlighted lines.
Add needed references, remove unnecessary references, resolve missing references
(from the menu: Tools, References...)

keep compiling until nothing happens (this is good!) -- then Save

also be sure, before compiling, to use Option Explicit at the very TOP of each module so variables that are not declared or are misspelled will be picked up by the compiler as well as many other errors than can be fixed before running.

~~~~~~~~~ Add Option Explicit ~~~~~~~~~

if the top of your module does not have a statement that says Option Explicit, then add this:
Code:
 Option Explicit  ' require variable declaration
If this was not done when the code was written, you will may need to DIM some variables -- it is best to do that anyway
 

strive4peace

AWF VIP
Local time
Today, 12:26
Joined
Apr 3, 2020
Messages
1,003
finally done commenting code so it compiles, whew! Looks like you might have copied forms to make new ones and then forgot about deleting the code behind it?
 

strive4peace

AWF VIP
Local time
Today, 12:26
Joined
Apr 3, 2020
Messages
1,003
I've attached an analysis of the SQL in your queries so you can see all the SQL in a Word document.

query for the subform on Note form = _filtru_materii_elev
this reference is wrong:
Forms!note.Form.m_anstudiu.value
Perhaps this should be: Forms!note!m_anstudiu ?

Click in the Navigation Pane and press Ctrl-F to turn on the Find/Filter box at the top if you want to paste the name to find it faster
 

Attachments

  • Query_Documentation_200406_049_evidstud_accdb.zip
    11 KB · Views: 101

Users who are viewing this thread

Top Bottom