Populating a Text control from SQL statement

I

Istari

I'd like to insert the result of an SQL query into a text field on a form.
My problem is that although my SQL works perfectly, the text control is
being updated with the actual Statement as opposed to the result. I'm sure
this must be something really silly that I'm overlooking.

my code looks as follows:

Dim sRateName As String

sRateName = "SELECT [RateTypes].[RateName]" & _
"FROM Rates INNER JOIN RateTypes ON
[Rates].[RateTypeID]=[RateTypes].[RateTypeID]" & _
"WHERE [Rates].[RateID] = " & Me.RateID

Me.AccBasisText = sRateName
 
G

gandalf

using dao

dim MySQLString as string 'holds the sql command
dim rRs as dao.recordset 'holds the data retrieved
mysqlstring=>"SELECT [RateTypes].[RateName]" & _
"FROM Rates INNER JOIN RateTypes ON
[Rates].[RateTypeID]=[RateTypes].[RateTypeID]" & _
"WHERE [Rates].[RateID] = " & Me.RateID

set rrs=currentdb.openrecordset(MYSQLSTRING)
if rrs.recordcount>0 then 'values present
Me.AccBasisText.value=
nz(rrs.fields("RateName"),"") 'assign
else
Me.AccBasisText.value ="none" 'assign litterally
end if
rrs.close 'free the recordset to minimize locking
set rrs=nothing

mind the wordwrap

had no time for testing it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top