Serving the Quantitative Finance Community

 
User avatar
NewtoRisk
Topic Author
Posts: 0
Joined: February 17th, 2006, 11:37 am

changing a field in access query via vba

March 26th, 2007, 10:12 am

hi all,i have a database with lots of queries and would like to create a loop in vba to go through them all and automatically set a field (all queries have a common field called "AsofDate") to a certain value. i have tried the below and failed so far.. For Each obj In dbs.AllQueries ' Set qdf = CurrentDb.QueryDefs(obj.Name) qdf.Fields("AsofDate").Value = "01/01/2007" Set qdf = Nothing Set dbs = Nothing Next objwould anyone know how to do this?regardsCT
 
User avatar
NewtoRisk
Topic Author
Posts: 0
Joined: February 17th, 2006, 11:37 am

changing a field in access query via vba

March 26th, 2007, 2:36 pm

Anyone ??? Any Idea ???
 
sjoo
Posts: 0
Joined: March 24th, 2003, 1:54 am

changing a field in access query via vba

March 27th, 2007, 7:58 am

hi,you're working on microsoft access!.I think that set dbs=Nothing in the loop makes you fail. pplz delete the line.and remove a comment mark from ' Set qdf = CurrentDb.QueryDefs(obj.Name) best regardssjoo
Last edited by sjoo on March 26th, 2007, 10:00 pm, edited 1 time in total.
 
User avatar
Doney
Posts: 0
Joined: June 24th, 2004, 7:14 am

changing a field in access query via vba

March 27th, 2007, 8:55 am

I think you also want to be going:qdf.Parameters("AsOfDate")="01/01/2007"rather than trying to set the value of a field (which sound a bit wierd!). I'm guessing you might really want it to be a data, not a string you're passing in, ieqdf.Parameters("AsOfDate") = #01-Jan-2007#What are you intending to do with the query afterwards? Even with these changes it won't actually do anything, you'll just be setting a parameter. This won't be reflected when you go to open any of the queries. Of course you may have removed some lines of code for clarity, and a iterating through the result set, which would work. If, however, what you are tryign to do is set a whole bunch of queries to open up for your given value date next time you open them, I'd suggest creating a one-row, one-field table, which you populate with your query date. Then your queries can just be linked onto that table, and you wouldn't need parameters.