?
Solved

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

Posted on 2007-11-20
3
Medium Priority
?
5,015 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1400 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 600 total points
ID: 20352959
Try =DMax("[DCTargetCompletionDate]", "KControl","ModuleID=1")
--
JimFive

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

770 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