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

how do I set the value of a field from theresults of a querry

Status
Not open for further replies.

avayaman

Technical User
Nov 6, 2002
841
CA
Lets call the query qry1 and it has a numerical field lets call tag.

How do i create VB routine to change the value of tag from 0 to one in all the entries produced by qry1?

qry1 is based on tbl1.

I am assuming I use a RunSQl routine of soem sort.



Paul Beddows

Consulting, Avaya/EAS implementation, Training
Vancouver, Canada
E-mail paul at natcoa.com
 
You can try something like the following. This assumes qry1 is updateable and tag is text (you did want to set it to 'one').
Code:
  Dim strSQL as String
  strSQL = "UPDATE qry1 SET tag = 'one' WHERE tag='0'"
  DoCmd.RunSQL strSQL
I generally like to set a database object and execute the sql.
Code:
  Dim strSQL as String
  Dim db As DAO.Database
  strSQL = "UPDATE qry1 SET tag = 'one' WHERE tag='0'"
  set db = Currentdb
  db.Execute strSQL, dbFailOnError



Duane
Hook'D on Access
MS Access MVP
 
actually I meant 1 not one. Let me try your suggestion.

Paul Beddows

Consulting, Avaya/EAS implementation, Training
Vancouver, Canada
E-mail paul at natcoa.com
 
You didn't mention the data type of the tag field. It's important to understand the difference between numeric, text, and date fields when creating SQL statements.

Duane
Hook'D on Access
MS Access MVP
 
Actually you inadvertently pointed me in the right direction. i created an update query to change the table values which in this particular application works well.

Paul Beddows

Consulting, Avaya/EAS implementation, Training
Vancouver, Canada
E-mail paul at natcoa.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top