Solved

How to print the result from a SQL command in acces

Posted on 2004-08-10
5
487 Views
Last Modified: 2012-05-05
i have a combo box where I select  card number.

Then on click I have a function "OnChange" that update  some textbox corresponding to the selected card number.

like Me.TextZone1 = DoCmd.RunSQL "SELECT [description] FROM [division] WHERE [NoDeCarte]=" & Me.ComboBox & " LIMIT=1"

But I want the result of the query to be printed in the textbox
0
Comment
Question by:BrunoTremblay
[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
5 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 11763699
Short code:
Me.TextZone1 = CurrentDb.OpenRecordset("SELECT [description] FROM [division] WHERE [NoDeCarte]=" & 
Me.ComboBox & " LIMIT=1").Fields("description").Value

Note that you might however do it with more lines to check errors etc;:

dim objRecord as Recordset
set objRecord = CurrentDb.OpenRecordset("SELECT [description] FROM [division] WHERE [NoDeCarte]=" & 
Me.ComboBox & " LIMIT=1")
if objRecord.eof and objRecord.bof then
   '-> no record found with the criteria...
else
   Me.TextZone1 = objrecord.Fields("description").Value
end if
objRecords.close
set objRecord = nothing

Cheers
0
 
LVL 18

Expert Comment

by:bonjour-aut
ID: 11763721

Dim rs As DAO.Recordset

mysql = "SELECT [description] FROM [division] WHERE [NoDeCarte]=" & Me.ComboBox & " LIMIT=1;"
Set rs = CurrentDb.OpenRecordset(mysql)
rs.MoveFirst
Me.TextZone1 = rs.fields(0)
rs.Close


regards, franz
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 11763772
do u need to put a AND in fromnt of LIMIT?


also how many records are you expecting to return?

if its lots, then use Franz's example, if its just the one record expected, then u could use DLOOKUP

Me.TextZone1 = DLOOKUP("description","division","NoDeCarte=" & Me.ComboBox & " AND LIMIT=1")

if NoDeCarte is a string

Me.TextZone1 = DLOOKUP("description","division","NoDeCarte='" & Me.ComboBox & "' AND LIMIT=1")
0
 

Author Comment

by:BrunoTremblay
ID: 11763898
DLookup really do it for me
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 11763922
no probs

just something else u need to know

if you dont find a match, DLOOKUP returns a null and that may fail
so wrap it with NZ or validate the return

Me.TextZone1 = NZ(DLOOKUP("description","division","NoDeCarte='" & Me.ComboBox & "' AND LIMIT=1"),"")



0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

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…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

739 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