Sie sind auf Seite 1von 3

Page 1 of 3

Dev Center

Search Office with Bing

Home

Products

Office 365

Docs

Samples

Downloads

Training

How To

Support

Office Dev Center >Microsoft Office for Developers Forums >Access for Developers > Change "Query1" SQL with new SQL using VBA

Change "Query1" SQL with new SQL using VBA


Search Access for Developers Forum h2fcell

Ask a question

210 Points

Tuesday, February 01, 2011 4:07 PM

Using Access 2007: I have a select query Query1 with the following SQL SELECT tblLowestFare.Dates, tblLowestFare.Package, tblLowestFare.Tourist FROM tblLowestFare; How do I change that SQL with the following SQL using VBA. SELECT tblLowestFare.Dates, tblLowestFare.Package, tblLowestFare.Superior FROM tblLowestFare; This is what I have so far. Private Sub cmdNext_Click() Dim sqlString As String sqlString = "SELECT tblLowestFare.Dates, tblLowestFare.Package, tblLowestFare.Superior " & "FROM tblLowestFare;" End Sub

Reply

Quote

http://social.msdn.microsoft.com/Forums/en-US/accessdev/thread/5c587... 4/24/2013

Page 2 of 3

All Replies
h2fcell

210 Points

Tuesday, February 01, 2011 4:33 PM

Got it myself.

Thanks. Private Sub cmdNext_Click() Dim db As DAO.Database Dim qdf As DAO.QueryDef Dim sqlString As String Set db = CurrentDb() Set qdf = db.QueryDefs("Query1") sqlString = "SELECT tblLowestFare.Dates, tblLowestFare.Package, tblLowestFare.Superior " & "FROM tblLowestFare;" qdf.SQL = sqlString End Sub

Marked As Answer by h2fcell

Tuesday, February 01, 2011 4:34 PM

Reply Quote

John P Spencer

2,280 Points
Tuesday, February 01, 2011

You could just add the following line CurrentDb().QueryDefs("Query 1").SQL = sqlString There might be a better solution, but I can't tell if there is since you have not explained why you need to change the SQL of the query. Since you are doing this in a form, my guess is that you might only need to assign the query sqlString as the record source for the form instead of changing the SQL property of the query.

http://social.msdn.microsoft.com/Forums/en-US/accessdev/thread/5c587... 4/24/2013

Page 3 of 3

John Spencer Access MVP 2002-2005, 2007-2011 The Hilltop Institute University of Maryland Baltimore County

Reply
OFFICE 2013

Quote
OFFICE EXTENSIBILITY Apps for Office Visual Studio (VSTO) Open XML Fluent UI VBA RESOURCES Office 2010 developer map Office 2007 developer map Office developer blog SDKs and references Office developer forums Training Microsoft community Videos Stack Overflow CONNECT Apps for Office and SharePoint blog

New features and capabilities Apps for Office Office 2013 training Try Office 365 ProPlus Preview

Newsletter

Privacy Statement

http://social.msdn.microsoft.com/Forums/en-US/accessdev/thread/5c587... 4/24/2013

Das könnte Ihnen auch gefallen