PC Review


Reply
Thread Tools Rate Thread

How to change MS Query via VBA

 
 
Andrew
Guest
Posts: n/a
 
      22nd Nov 2008
Hi,

The following codes excecutes of but doesn't do what I expect. I want it to
change the MS Query but it remains as is after I run this code. By changing
the sSQL statements I expect the query to change. Any ideas?



Sub Change_MS_Query()
The_Path = "G:\00_cen\Oth\Inventory Planning Reports\POL\"
Access_Filename = "POL"
'Both Dept & Report Period
sSQL = "SELECT tbl_Comm_Data.[Commitment Status],
tbl_Comm_Data.CURR_DATE FROM Tbl_Report_Periods INNER JOIN (Tbl_Dept_No INNER
JOIN tbl_Comm_Data ON Tbl_Dept_No.The_Dept = tbl_Comm_Data.DEPT_NO) ON
Tbl_Report_Periods.REPORT_PERIOD = tbl_Comm_Data.REPORT_PERIOD;"
'Dept only
'sSQL = "SELECT tbl_Comm_Data.[Commitment Status],
tbl_Comm_Data.CURR_DATE FROM Tbl_Dept_No INNER JOIN tbl_Comm_Data ON
Tbl_Dept_No.The_Dept = tbl_Comm_Data.DEPT_NO;"

Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlExternal)
DBFile = The_Path & Access_Filename & ".mdb"
ConString = "ODBC;DSN=MS Access Database;DBQ=" & DBFile
QueryString = sSQL

With PTCache
.Connection = ConString
.CommandText = QueryString
End With
Debug.Print PTCache.CommandText
MsgBox PTCache.CommandText
End Sub


--
Andrew
211108

Option Compare Database

Private Sub Command0_Click()
Dim qdfNew As DAO.QueryDef
Dim strSQL As String

'Both Dept & Report Period
sSQL = "SELECT tbl_Comm_Data.[Commitment Status],
tbl_Comm_Data.CURR_DATE FROM Tbl_Report_Periods INNER JOIN (Tbl_Dept_No INNER
JOIN tbl_Comm_Data ON Tbl_Dept_No.The_Dept = tbl_Comm_Data.DEPT_NO) ON
Tbl_Report_Periods.REPORT_PERIOD = tbl_Comm_Data.REPORT_PERIOD;"
'Dept only
'sSQL = "SELECT tbl_Comm_Data.[Commitment Status],
tbl_Comm_Data.CURR_DATE FROM Tbl_Dept_No INNER JOIN tbl_Comm_Data ON
Tbl_Dept_No.The_Dept = tbl_Comm_Data.DEPT_NO;"

Set qdfNew = CurrentDb.CreateQueryDef("qry_Comm_Data", sSQL)


End Sub

--
Andrew
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Revise an Append Query, or Change to an Update Query MJ Microsoft Access Queries 3 12th Feb 2010 08:59 PM
Change recordset, change query SQL, works...try again and requery...doesn't Paolo Microsoft Access Form Coding 0 31st Jul 2006 02:25 PM
Change recordset, change query SQL, works...try again and requery...doesn't Paolo Microsoft Access VBA Modules 0 31st Jul 2006 02:25 PM
Change Text to Integer Using a Query/Data Definiation Query =?Utf-8?B?QUo=?= Microsoft Access 3 3rd Feb 2005 08:09 PM
Change in Table not reflected in QUERY unless you CLOSE/OPEN query me Microsoft Access Queries 0 21st Aug 2003 10:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:44 PM.