Solved

Putting SQL statement into control source of MS Access unbound text box

Posted on 2007-11-20
3
4,798 Views
Last Modified: 2013-11-28
Hi experts,

I am trying to place an SQL into an unbound field on my form.  The SQL is intended to return the maximum date in a field where moduleID = 1.   My SQL is as follows:

=(SELECT Max([DCTargetCompletionDate]) AS Expr1 FROM KControl WHERE ModuleID=1;)

I am getting #Name as a result and do not know how to get round this.

Can anybody help?

Thank you.
Terry
0
Comment
Question by:TerenceHewett
  • 2
3 Comments
 
LVL 3

Expert Comment

by:pmctrek
ID: 20320631
Why dont you add the SELECT to the datasource for the form and bind the test box to that new field?
0
 
LVL 3

Accepted Solution

by:
pmctrek earned 350 total points
ID: 20320856
The problem is that bound objects like text boxes can only access the forms recordset.  If the data you want is outside the recordset then you need to look it up some other way.  The attached code is a simple way to set the vaule of a field as the form is being rendered.
Private Sub Form_Current()

    Dim intI As Integer

    Dim fld As Field
 

    Set rst = New ADODB.Recordset

    rst.Open "SELECT Max([DCTargetCompletionDate]) AS CompDate FROM KControl WHERE ModuleID=1;", CurrentProject.Connection, adOpenKeyset, adLockOptimistic

    Text0.Value = rst.Fields("CompDate")

End Sub

Open in new window

0
 
LVL 15

Assisted Solution

by:JimFive
JimFive earned 150 total points
ID: 20352959
Try =DMax("[DCTargetCompletionDate]", "KControl","ModuleID=1")
--
JimFive

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now