Solved

How to print the result from a SQL command in acces

Posted on 2004-08-10
5
479 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
5 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
DLookup really do it for me
0
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

772 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

15 Experts available now in Live!

Get 1:1 Help Now