Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 21st, 2007, 10:53 AM
Registered User
 
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default dynamically constructed sql action query

Hi all and thanks in advance for any help you might be able to provide,

I have a query that looks at a data table of risk item (questions) responses as fields (this is legacy data I am trying to incorporate) and then uses another query to find the recode value to construct a sql query string. I am using this approach because the questions that comprise the scale can change or or be modified and because I want the user to be able to select all risks or a risk domain (a risk type).

Here is the query I have made:

SELECT "UPDATE [rcData] SET [rcData].[" & [Variable] & "] = " & Nz([qryGetValues].[rcValue],"NULL") & " WHERE ([rcData].[" & [Variable] & "] = " & [qryGetValues].[Valuenumber] & ")" AS strSource, qryGetValues.fkRisks, qryGetValues.ID, qryGetValues.rcValue, qryGetValues.Variable, qryGetValues.Valuenumber, qryGetValues.Valuelabel
FROM qryGetValues
WHERE ((("UPDATE [rcData] SET [rcData].[" & [Variable] & "] = " & Nz([qryGetValues].[rcValue],"NULL") & " WHERE ([rcData].[" & [Variable] & "] = " & [qryGetValues].[Valuenumber] & ")") Not Like "*" & "] = WHERE (" & "*"))
ORDER BY qryGetValues.Valuenumber;



I have tried making a macro and converting it to vba it is as follows:

Function mroRecode()
On Error GoTo mroRecode_Err

    DoCmd.OpenQuery "qryRecode", acViewNormal, acReadOnly
    DoCmd.RunSQL "qryRecode!strSource.value", -1
    DoCmd.FindNext


mroRecode_Exit:
    Exit Function

mroRecode_Err:
    MsgBox Error$
    Resume mroRecode_Exit

End Function

I am really more of a data person than a programmer, so I think it needs a loop maybe? Any ideas?
 
Old August 21st, 2007, 12:35 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I am still not sure the actions this should be taking. What is the flow control? Are you trying to update all of your legacy data at once, or just as needed? The query syntax seems wrong. I would try breaking this into several queries and then looping inside the queries as you iterate through a larger recordset.

What does the data look like before the action, and what should it look like after? Then we can do flow control.

HTH

mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Output Query to txt file from SQL Query everest SQL Server 2005 4 November 22nd, 2007 01:49 AM
Request action on change and get no action. Help crussell Ajax 0 September 12th, 2007 11:11 AM
dynamically query MRvLuijpen Access VBA 3 September 28th, 2006 07:46 AM
Dynamically Changing SQL Commands? avantjer BOOK: Professional Crystal Reports for VS.NET 2 May 18th, 2004 11:29 PM
Dynamically query MRvLuijpen Access 8 July 12th, 2003 09:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.