Accessing query

  • Thread starter Thread starter ElCabron
  • Start date Start date
E

ElCabron

Guest
Hi,

I have to take a single value from a query to a field in a form. I can't make up an update query because the form locks the table used.

What would be missing in that code?

stDocName = "MyQuery"
DoCmd.OpenQuery stDocName, acNormal, acEdit
Me.MyField.Value = (??? what here?)

(I want to access the result of my query)

Any idea? Thanks!

Sebastien
 
Capture the results of your query in a recordset.

Dim db as database
Dim rs as recordset

set db = currentdb
set rs = db.openrecordset("MyQuery")

me.MyField = rs.fields(n)


Where "n" is the field number that contains the data you need. Keep in mind that the Fields collection is zero based, so the first field in the query is actually (0). If you wanted to grab the daa in the fifth field, you would enter...

me.MyField = rs.fields(4)
 
Or you could just use DLookup
 

Users who are viewing this thread

Back
Top Bottom