Combining VBA with SQL

PrincessBretti

Registered User.
Local time
Today, 09:45
Joined
Mar 16, 2000
Messages
14
Ok heres my code:

Dim strSQL As String
strSQL = "select [First name], [last name] from [contact details]
where [client reference number] = "
& Me.Client_Reference_Number

Me.txtName = "Appointment Details for " & strSQL

But of course this just types out the sql statement instead of running it and appending it to the text...

How can I make the sql execute and append on to the text?

I am at work and for some reason none of the Access help files will work... so I can't work this out myself
frown.gif


Anybody???

Cheers

Princess Bretti
 
The following should work.

Dim strSQL As String, db as Database, rs as Recordset
strSQL = "select [First name], [last name] from [contact details]
where [client reference number] = "
& Me.Client_Reference_Number

Set db=CurrentDb
Set rs=db.OpenRecordSet(strSQL)

Me.txtName = "Appointment Details for " & rs![First Name] & " " & rs!{Last Name]


HTH
 
Alternativel'y, a 'quick and dirty' non-SQL method would be:

Me.txtName = "Appointment Details for " & DLookup("[First name] & ' ' & [last name]","[contact details]","[client reference number] = " & Me.Client_Reference_Number)

Mike
 

Users who are viewing this thread

Back
Top Bottom