1. Create your calculated field to do whatever you need
2. Create a new query, add the fields you want
3. For the field you where want the calc field as criteria, put the following exprssion in the criteria line:
[Forms]![YourFormName]![CalcFieldName]
- As a side note, if you want to refer to a calc field on a subform, use this variation on the language:
[Forms]![MainFormName]![SubfomName].[Form].[CalcFieldName]
For the query to run, the form needs to be open (if not, Access will give you a dialog asking you to manually enter criteria).
If it has a name you can use it, assuming of course there is some type of match on a table somewhere. Assuming the name of this unbound calculated field is unkfld and when computed it points to the primary key(pk) of some other table; then all you have to do is build the sql statement. Assuming it is a simple select query, something like this will do the trick for you.
Dim strsql as string
Dim rs as recordset
Strsql = “select * from some_table where pk = “ & me.unkfld.value
Set rs = currentdb.openrecordset (strsql, dbopendynaset)
You’ve done it.
This assumes that unkfld is numeric. If it is text, your sql string will incorporate double quotes like this.
Strsql = “select * from some_table where pk = ‘” _
& me.unkfld.value & “’”
Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
This was an example based on your criteria.
What is it you do not understand or disagree with? Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
I have a unbound calculated field on a form which is not linked to a table. So how do I link this to a table when you discuss matching it to a table and when computed it points to a primary key of some other table.
As I said, it was an example. Usually you use an unbound control to compute somevalue that points to something. You don't have to. You can use it to do whatever you want to do with it. Thew only point I attempted to make was to answere your question, ie, can you use a unbound variable on a form in a query and the answe is yes. Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.