Query results to textbox

SteveGr

Registered User.
Local time
Today, 08:35
Joined
Aug 2, 2002
Messages
65
Hi all,

How do I run a query and have the result show in a textbox on my form? I have already created my query but not sure how to get the results in the textbox

Thanks, SteveG
 
Steve,

Never come across a request to put query data into a text box? Why don't you just build a main or sub form on that query??
 
Not sure what you're trying to do but you can use DLookUp on the query, if you explain the reasons then there may be better ways
 
Use a querydef recordset to return the result and store it in a form textbox, esp.

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qdf As QueryDef
Dim sSQL As String

Set db = CurrentDb
sSQL = "your sql string which returns one record"
Set qdf = db.CreateQueryDef("", sSQL)
Set rs = qdf.OpenRecordset(dbOpenSnapshot)
'no error check has be shown for no records being returned because of back criteria or just no result
rs.movefirst
Forms!yourForm!txtBox = rs.fields(i) 'where i=0 to N-1 fields to pickup the field your want
rs.close
db.close
set rs=nothing
set db=nothing
 

Users who are viewing this thread

Back
Top Bottom