[AccessD] Using a dynamic recordset field.

Darryl Collins Darryl.Collins at iag.com.au
Wed Aug 18 22:42:38 CDT 2010


_______________________________________________________________________________________

Note: This e-mail is subject to the disclaimer contained at the bottom of this message.
_______________________________________________________________________________________


Hi all,

I am hoping this is simple, but I cannot seem to get my head around the solution and it is rather tricky to google.

The problem is simple

I have a line in code like this

Dim strField as string

gstrSQL = "SELECT " & strField & " FROM tblWhatEver"
Set rsDAO = DBEngine(0)(0).OpenRecordset(gstrSQL)

' THIS WORKS:
if rsDAO.Recordcount > 0 then
	dblValue = rsDAO!AD
end if

WHAT I WANT (and it doesn't work):
if rsDAO.Recordcount > 0 then
	dblValue = rsDAO!" & strField
end if

Can I make the fieldname after the '!' dynamic?  and what is the syntax?

cheers
Darryl.


_______________________________________________________________________________________

The information transmitted in this message and its attachments (if any) is intended 
only for the person or entity to which it is addressed.
The message may contain confidential and/or privileged material. Any review, 
retransmission, dissemination or other use of, or taking of any action in reliance 
upon this information, by persons or entities other than the intended recipient is 
prohibited.

If you have received this in error, please contact the sender and delete this e-mail 
and associated material from any computer.

The intended recipient of this e-mail may only use, reproduce, disclose or distribute 
the information contained in this e-mail and any attached files, with the permission 
of the sender.

This message has been scanned for viruses.
_______________________________________________________________________________________




More information about the AccessD mailing list