Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting Value from Recordset

Status
Not open for further replies.

plowmon

IS-IT--Management
May 24, 2001
3
CA
I have a piece of code that I use to find values that enable fields on a form. Here is an excerpt of the code:

Set rst = [domain groups]
strSearchName = Str(Me!Manager)

rst.FindFirst "Manager = " & strSearchName
Group = rst.[Group]
Me!Group.Enabled = True

The problem is that I want to take the value stored in the Group field of the Recordset from the FindFirst instruction. I am getting an error on the Group = rst.[Group] line. What is the proper syntax to extract only the value from the specific field in the recordset?

Thanks
Jeff
 
rst.fields("Fieldname") is proper but can be shortened to
RST!fieldname
 
Thanks - I tried this and I don't get the syntax error, but now I am getting a runtime error '2465' "Access can't find the field specified. It is happenning on the line rst = [domain groups], where domain groups is a table in the DB. Is there another way to define the recordset? Or if you are aware of any sites that list more specific descriptions of the runtime errors, let me know.

Cheers
Jeff
 
I sugggest you post the whole code here for review

Set rst = [Domain groups] should look more like
set rst = db.openrecordset("domaingroups")
my suggested method would be

dim db as database, rst as recordset
dim strsql as string,strcrit as string
dim strvariable as string
'this builds the recordset selection
strsql ="select fieldwithdata from your table where "
strcrit = "fieldwithdata = " me.fieldtomatchonform
'if field is text use Quotes "field = '" & match & "'"
strsql = strsql & strcrit

set db = currentdb 'tells which database to find the records
set rst = db.Openrecordset(strsql) 'opens the recordset

with rst
if .count >= 1 then 'makes sure there are records returned
.movefirst 'moves to the first record
strvariable = !fieldwithdata 'sets the value
end if
.close 'closes recordset
end with
debug.print strvariable 'prints value to debug window

good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top