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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access a query from a form

Status
Not open for further replies.

GabberGod

IS-IT--Management
Nov 16, 2003
73
0
0
AU
Ok basicly I have a coded event that runs a query should the circumstances be correct. what i want to do is copy the data from the fields in the query to the fields in the form.

say i have a form named Items with a field named Supplier

and i have a query named item_udate with a field named supplier

Can i do something like this

[supplier] = [Queries]![item_udate]![supplier]

if so what is the exact syntax, or how else should i do it??? possibly using dlookup?
 
There are a lot of ways you can do that. First, if you are doing all of this from a form, you could bind the field in the form to the field in the query, then when the circumstances are correct, do a me.requery on the form.

Another way of doing it would be to leave the field unbound and use a recordset to change the field:

rstSupplier = Currentdb.Querys("item_update").openrecordset
me.supplier = rstSupplier!Supplier

I think most people opt for the first method, but if you haven't worked with forms before its probably a bit confusing. Hope that helps!

- Tom
 
You can use DLookup or recordset. Since you already know about DLookup, here's an alternative using recordset (adjust as needed).

Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset(query)

supplier = rs.Fields("supplier")

rs.Close
db.Close

I prefer DLookup just because it's shorter.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top