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

Help please to get value of a TextBox into the Criteria of a Query.

Hi
O.S. = Windows XP Pro all Service Packs
Access = 2003

I have a form with 2 tabbed pages. On the second page I have a subform which populates in Datasheet view with a list of items. One Column has the title Job Number.
When I click on one of the record selectors (little boxes to left of the first used column) the Job Number is written into a Global Variable. Have checked and this works fine.
I have a Command Button on the form below the subform, that after clicking on a job(in the subform) I want to open a new form based on a query that takes the Value of the Job Number selected and populates the new form with all the fields and data accociated with the Job Number selected.
The final few words of the query look something like this (have not got work PC in front of me) ..WHERE ((JobNumber)=([txtJobNumber.Value])) or I can change it to WHERE (JobNumber = (lngJobNumber)).
The problem is that when I push the command button instead of the new form opening and populating, a small box pops up on screen asking me to enter a value for txtJobNumber.Value or lngJobNumber(This is the Variable I have used that holds the Value of what was in the TextBox txtJobNumber.Value.)

Can I get the query to somehow just accept the value direct from the TextBox or Variable?

Any help much appreciated I have seen another couple of similiar questions on this site, one that is close seemed to suggest writing a function that would pass the value? I'll try that today.
Nov 25 '06 #1
14 3515
NeoPa
32,556 Expert Mod 16PB
I have posted a function earlier in another thread (Use selected record in Form B (acDialog Form) as go to criteria in Form A) to give this facility.
However, I think there is a more valid way of doing this with forms and subforms.
Obviously you're welcome to use the solution posted there but I think it's a bit of a kludge for your situation.
We have a bit of a form / subform expert on here, give her a chance to post here as I think she can give you the 'proper' answer.
If not of course, use the kludge.
Nov 26 '06 #2
Thanks NeoPar

I'll have a look at the Kludge as you call it now.

Just for a bit more info, I tried this afternoon to make up a .bas module with a function in it and have the Query obtain the required parameter from that function but still no go. I have done this previously and I'm sure it worked. Makes me wonder if the Query does not know how to look at the subform on the tabbed page of the form. The subform is not linked but gets the data that populates it from another query when it is opened. This works fine.

The Main Form is called frmFieldServiceDatabase. it consists of 2 tabbed pages. The second of which contains the unlinked subform.

Thanks again I'll go have a look now at the Kludge!!
Nov 26 '06 #3
NeoPa
32,556 Expert Mod 16PB
I'm no expert on sub-forms, but I do know that referring to an element on a sub-form has to include the name of the Tab it's on, rather than the name of the sub-form itself in the reference.
This may help your code.
BTW Our main forms expert expects to be away for a short while, so please bear with us.
Others may very well step in mind you.
Another BTW, How do you get BBB frm BeeBleBrox? That can't be right surely ;).
Nov 26 '06 #4
ADezii
8,834 Expert 8TB
Hi
O.S. = Windows XP Pro all Service Packs
Access = 2003

I have a form with 2 tabbed pages. On the second page I have a subform which populates in Datasheet view with a list of items. One Column has the title Job Number.
When I click on one of the record selectors (little boxes to left of the first used column) the Job Number is written into a Global Variable. Have checked and this works fine.
I have a Command Button on the form below the subform, that after clicking on a job(in the subform) I want to open a new form based on a query that takes the Value of the Job Number selected and populates the new form with all the fields and data accociated with the Job Number selected.
The final few words of the query look something like this (have not got work PC in front of me) ..WHERE ((JobNumber)=([txtJobNumber.Value])) or I can change it to WHERE (JobNumber = (lngJobNumber)).
The problem is that when I push the command button instead of the new form opening and populating, a small box pops up on screen asking me to enter a value for txtJobNumber.Value or lngJobNumber(This is the Variable I have used that holds the Value of what was in the TextBox txtJobNumber.Value.)

Can I get the query to somehow just accept the value direct from the TextBox or Variable?

Any help much appreciated I have seen another couple of similiar questions on this site, one that is close seemed to suggest writing a function that would pass the value? I'll try that today.
The correct syntax for referring to a Field Value on a Sub-Form from the Main
Form is as follows:

Forms![frmMainForm].[subfSubFormName].Form![FieldName]

P.S. There should be no need to refer to the specific Page on the Tabbed Dialog
Control
Nov 26 '06 #5
NeoPa
32,556 Expert Mod 16PB
The correct syntax for referring to a Field Value on a Sub-Form from the Main
Form is as follows:

Forms![frmMainForm].[SubFormName].Form![FieldName]

P.S. There should be no need to refer to the specific Page on the Tabbed Dialog
Control
Thanks, that's right.
Bear in mind though, (not you ADezii - I'm sure you know already) that the SubFormName refers to the name of a container type item on the main form and not the name of the form within. Also, the Form![FieldName] is actually spelt 'Form' and is not intended to represent the name of the actual form used either.
I'm not sure how subforms are handled on tabbed forms ATM but I don't even want to go there just now ...Because life's complicated enough!
Nov 26 '06 #6
Hi ADezii and NeoPar

Many thanks for the format for getting the value into the criteria. It worked fine once I got the correct names of the forms into the expression.

One thing I find difficult to follow it that in my Forms List the subform is named 'frmReviewJobsSubform,' however if I click on the subform itself in Design View it says 'qryReviewJobs subform' and when I entered the last version into the Function it worked... i.e. FindJob = Forms![frmFieldServiceDatabase]![qryReviewJobs subform].Form![txtJobNumber].

IF you have a moment could you please explain the syntax of the statement to me... i.e. Why use . between Forms and why have the final..... '].Form![txtJobNumber] why do you need the word form there??

Anyway much appreciate your time and help.
Kind Regards
Mike
Nov 26 '06 #7
NeoPa
32,556 Expert Mod 16PB
'.' means the following is the name of a property of the parent.
In collections though, you have something similar to an array of like properties.
Take the Forms() collection, for instance. This is the collection of open forms.
Normal reference usage is Forms(Name of form), but VBA has provided another, more convenient way of writing that which is Forms![Name of Form] ([] only necessary with chars like spaces which would confuse the compiler otherwise).
So, Forms("MyForm") ==> Forms!MyForm.

So, the '!' is used to identify an element in a collection whereas the '.' identifies a defined property of an object. Where '!' is used and is not required, the compiler will treat it as a '.'.
Forms() is a collection of Form objects.

Clear as mud yet?
Nov 26 '06 #8
NeoPa
32,556 Expert Mod 16PB
FindJob = Forms![frmFieldServiceDatabase]![qryReviewJobs subform].Form![txtJobNumber].

IF you have a moment could you please explain the syntax of the statement to me... i.e. Why use . between Forms and why have the final..... '].Form![txtJobNumber] why do you need the word form there??
Mike
In this case, it could have been written as (someone correct me if I'm wrong but I tried it out on my test forms and it worked ok)
Expand|Select|Wrap|Line Numbers
  1. FindJob = Forms!frmFieldServiceDatabase.[qryReviewJobs subform].Form.txtJobNumber
  2. or
  3. FindJob = Forms("frmFieldServiceDatabase").[qryReviewJobs subform].Form.txtJobNumber
Notice the [] around 'qryReviewJobs subform' as it has an embedded space.
I still don't seem to have answered the question!
[qryReviewJobs subform] is actually a containing object property of the main form.
One of the properties of this type of object is .Form, which refers to the subform itself.
I don't know why it's structured this way - and it certainly confuses lots of people - but that's how it is :S.

Final addendum - The container part doesn't necessarily have the same name as the actual form that is contained in it.
I'm not sure it can, but it certainly needn't.
Nov 27 '06 #9
Hi Neopa

Thanks for the explanation...dont know about clear as mud but its getting there!!
Just for interest sake I cant view this site very well from my work laptop. In a lot of the threads/questions the text in lines runs into the line above or below.

Anyway much appreciate your assistance. Thanks!
Dec 1 '06 #10
MMcCarthy
14,534 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. FindJob = Forms("frmFieldServiceDatabase").[qryReviewJobs subform].Form.txtJobNumber
  2.  
This is not quite right Ade

Expand|Select|Wrap|Line Numbers
  1. Forms("FormName").Controls("ControlName")
  2.  
Is the syntax. I don't know if there is anyway to reference a control on a subform using this syntax.

In this case, it could have been written as (someone correct me if I'm wrong but I tried it out on my test forms and it worked ok)
Expand|Select|Wrap|Line Numbers
  1. FindJob = Forms!frmFieldServiceDatabase.[qryReviewJobs subform].Form.txtJobNumber
  2. or
  3. FindJob = Forms("frmFieldServiceDatabase").[qryReviewJobs subform].Form.txtJobNumber
Notice the [] around 'qryReviewJobs subform' as it has an embedded space.
I still don't seem to have answered the question!
[qryReviewJobs subform] is actually a containing object property of the main form.
One of the properties of this type of object is .Form, which refers to the subform itself.
I don't know why it's structured this way - and it certainly confuses lots of people - but that's how it is :S.

Final addendum - The container part doesn't necessarily have the same name as the actual form that is contained in it.
I'm not sure it can, but it certainly needn't.
Dec 1 '06 #11
MMcCarthy
14,534 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. FindJob = Forms("frmFieldServiceDatabase").[qryReviewJobs subform].Form.txtJobNumber
  2.  
This is not quite right Ade

Expand|Select|Wrap|Line Numbers
  1. Forms("FormName").Controls("ControlName")
  2.  
Is the syntax. I don't know if there is anyway to reference a control on a subform using this syntax.
You could try...

Expand|Select|Wrap|Line Numbers
  1. Forms("FormName").Controls("SubFormName").Form.TextBoxName
  2.  
Dec 1 '06 #12
NeoPa
32,556 Expert Mod 16PB
This is not quite right Ade
Yes it is. It's perfect.
What else would you expect ;)

-Ade.
Dec 3 '06 #13
ADezii
8,834 Expert 8TB
Hi ADezii and NeoPar

Many thanks for the format for getting the value into the criteria. It worked fine once I got the correct names of the forms into the expression.

One thing I find difficult to follow it that in my Forms List the subform is named 'frmReviewJobsSubform,' however if I click on the subform itself in Design View it says 'qryReviewJobs subform' and when I entered the last version into the Function it worked... i.e. FindJob = Forms![frmFieldServiceDatabase]![qryReviewJobs subform].Form![txtJobNumber].

IF you have a moment could you please explain the syntax of the statement to me... i.e. Why use . between Forms and why have the final..... '].Form![txtJobNumber] why do you need the word form there??

Anyway much appreciate your time and help.
Kind Regards
Mike
'Keep in mind that you will rarely, if ever, actually refer to the name of the Form
'comprising a Sub-Form. You will actually be referring to the name of the
'Sub-Form control. The actual Sub-Form itself is derived from the Form property
'of the Sub-Form Control. As it applies to your individual case, this would be:
Forms![frmFieldServiceDatabase]![qryReviewJobs subform].Form

NOTE: I sincerely apologize if I have made matters more confusing - there
seems to be no easy way to explain this syntax.
Dec 3 '06 #14
NeoPa
32,556 Expert Mod 16PB
As ADezii so clearly says, this is not a simple concept to understand.
(Thank you again ADezii - another good, helpful post).
I will just copy in here something I set up and saved, to help clarify this particular issue.
It doesn't contradict anything ADezii has already said but hopefully shows from a slightly different angle.

The external syntax (code running from outside the form itself or one of its subforms) for this is :
Expand|Select|Wrap|Line Numbers
  1. Forms![FormName].[SubFormName].Form.[ControlName]
  2. or
  3. Forms("FormName").[SubFormName].Form.[ControlName]
Where :
FormName is the name of the main form.
SubFormName is the name of the Sub-form control on the main form in which the actual sub-form is contained.
ControlName is the name of the control that you want to refer to.

You will often see (!) used instead of (.). In most cases it's not a problem as Access will interpret it as a (.) if object it refines is not a collection.
Example to refer to the subform's txtJobNumber control :
Expand|Select|Wrap|Line Numbers
  1. Forms!frmFieldServiceDatabase.[qryReviewJobs subform].Form.txtJobNumber
  2. or
  3. Forms("frmFieldServiceDatabase").[qryReviewJobs subform].Form.txtJobNumber
Dec 3 '06 #15

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

Similar topics

1
by: PerryC | last post by:
Can someone help me accomplish the following in a MSAccess Report: 1. Check if Me.Discipline = "RN" (within the source query) 2. Then check the Me.YearOfEmployment: (again within the same source...
5
by: Steve Patrick | last post by:
Hi All You guys are my last hope, despite spending money on books and hours reading them I still can not achieve the results I need. I have designed a database in Access 2000 based on 1 table,...
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
10
by: motessa | last post by:
Hello All, I am new to Access and have been looking for answers to my problem on the internet and have not found it yet. I hope someone can give me a hint. Thanks so much. I have a form...
7
by: Aaron | last post by:
Complete code follows. I am new to .NET programming (and programming in general) and I am having a difficult time understanding how to fill a variable in one sub, and then access it from...
10
by: molen malat | last post by:
i have a query with 4 fields, and a form based on it. i put another 4 textbox to get criteria to filter the query. the query runs normally when all the textbox have a value (not null) but when one or...
2
by: Haas C | last post by:
Hey all, I created a Query (in Design View) which asks the user for an "As Of Date" which would then display relevant data. I put in the Criteria Row of the Query Design for the Date field. Is...
9
by: pic078 via AccessMonster.com | last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files) that remains stuck in task manager after exiting the application - you can't reopen database after exiting as a result...
4
by: pankajsingh5k | last post by:
Hi guys, These question is for all the experts... Please help me before my brain explodes The problem is again with the formview control.. I have a formview and i have to use it that...
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$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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 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.