Solved

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

Posted on 2007-11-20
3
4,944 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 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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