Solved calling the value of a field from a main form -> subform into a query

VasiuF

Member
Local time
Today, 09:13
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:
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:
I'm guessing that this would be:

forms!start_meniu!Note1.form.m_anstudiu ASSUMING that the subform control NAME property is Note1
 
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
 
Is this a case of subform loading before mainform?
 
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
 
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
 
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.
 
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
 
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.
 
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
 
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 ...
 
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
 
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: 116
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.
 
The source for frmDetaliu is selected from the right buttons, the default is _frmArma
 
~~~~~~~~~ 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
 
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?
 
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

Users who are viewing this thread

Back
Top Bottom