Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 358
Default How to change MS Query via VBA

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:=xlExter nal)
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Server for Query Cinco Excel Discussion (Misc queries) 3 July 31st 09 01:04 AM
How to change an existing query Gireeshm Excel Discussion (Misc queries) 0 July 18th 06 12:33 PM
can't change field name in query? rachael Links and Linking in Excel 4 February 7th 06 07:48 PM
Change Connection of a Query Jean-Francois Excel Discussion (Misc queries) 1 October 6th 05 12:16 AM
change query path shin Excel Programming 0 June 17th 05 04:12 PM


All times are GMT +1. The time now is 05:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"