Solved

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

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

776 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