All source code in Visual Basic Ask a Visual Basic Pro Discussion Forum Categories All jobs in Visual Basic
piece,code,will,extract,statement,embedded,wi
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Visual Basic Stats

 Code: 5,128,645. lines
 Jobs: 275. postings

 How to support the site

 
Sponsored by:
Quick Search for:  in language:    
You are in:
 
Login





Latest postings for Visual Basic.
Click here to see a screenshot of this code!DMmessagbox
By Frank Donckers on 2/9

(Screen Shot)

The Laser - Entrance Exam Creator
By Le Chevalier on 2/8


Click here to see a screenshot of this code!WiiNi Metur
By Dimityr Ivanov on 2/8

(Screen Shot)

Simple traductor de archivos INI
By Miguel Angel Esquef on 1/28


Click here to see a screenshot of this code!Resistor Color Code
By Ferdinand Viray on 2/7

(Screen Shot)

Click here to see a screenshot of this code!Database - Student Reccord
By Ferdinand Viray on 2/7

(Screen Shot)

Click here to see a screenshot of this code!Online Text Based Winsock Crime Game | Mafia Game
By William Hughes on 2/7

(Screen Shot)

Click here to see a screenshot of this code!NZB Reader III
By Ed Wilk on 12/29

(Screen Shot)

Click here to see a screenshot of this code!Jobz Tracker
By Andy J Spry on 2/6

(Screen Shot)

Click here to see a screenshot of this code!Database - Student Reccord
By Ferdinand Viray on 2/6

(Screen Shot)

Click here to see a screenshot of this code!Resistor Color Code
By Ferdinand Viray on 2/6

(Screen Shot)

a simple program (database)
By Jenilyn Brena on 2/6


Click here to see a screenshot of this code!Multipass BILATERAL FILTER. (V3.3)
By reexre on 1/12

(Screen Shot)

Click here to see a screenshot of this code!Completely hide taskbar in vista and seven.
By Alexander G on 2/5

(Screen Shot)

Binding DataGrid to ADODC
By kývanç ; on 2/5


Book Record
By kývanç ; on 2/5


VB6 to VB.NET Guide
By brandon teoh on 2/5


Easy dsr datareport
By Manuel Matamoros on 2/4


Click here to see a screenshot of this code!Manual RAID 1 v2.0.11
By Mike Morrow on 1/11

(Screen Shot)

Rotate Text Pure Vb, No Dll, No Api
By ivan pausich on 2/4


Click here to see a screenshot of this code!MediaVusion; A Powerful Media Player
By xvader on 2/4

(Screen Shot)

Click here to see a screenshot of this code!PSC Zip Store and read
By Kenneth Foster on 2/3

(Screen Shot)

Click here to see a screenshot of this code!Linear Power Supply Designer
By RandyT_CS on 2/3

(Screen Shot)

retrieve (get) all system services
By milad ghafooreyan on 2/3


Click here to see a screenshot of this code!easy inventory manager
By ravi vaghela on 2/3

(Screen Shot)

Click here to see a screenshot of this code!A simple Calculater in Vb 6
By Varun Naharia on 2/2

(Screen Shot)

Click here to see a screenshot of this code!Special Folder Locator
By dreamvb on 2/2

(Screen Shot)

Click here to see a screenshot of this code!material viewer system
By Donald Paras on 2/2

(Screen Shot)

Click here to see a screenshot of this code!Solid Lathe Simulation
By Eduardo Capatto Júnior on 2/1

(Screen Shot)

Click here to see a screenshot of this code!A simple Calculater in Vb 6
By Varun Naharia on 1/31

(Screen Shot)

Click here to see a screenshot of this code!Final Fantasy 3D game
By Yazan Markabi on 1/31

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!



 
 
   

Extract Query Text from MsAcces

Print
Email
 
VB icon
Submitted on: 8/12/2008 1:28:04 PM
By: Joseph Varghese 
Level: Intermediate
User Rating: Unrated
Compatibility:VB 6.0, VBA MS Access

Users have accessed this code 2152 times.
 
author picture
(About the author)
 
     This piece of code will extract the sql statement embedded within and MS-Access Query, If you have any other solutions pls let me know, else if found useful pls don’t forget to vote If any bugs/ suggestions found pls inform me too so that I can do the same in my library (As there are many type of queries, I will say this is not 100%)
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

'**************************************
' Name: Extract Query Text from MsAcces
' Description:This piece of code will ex
'     tract the sql statement embedded within 
'     and MS-Access Query, If you have any oth
'     er solutions pls let me know, else if fo
'     und useful pls don’t forget to vot
'     e
If any bugs/ suggestions found pls inform me too
so that I can Do the same In my library (As there are many Type of queries, I will say this is Not 100%)
' By: Joseph Varghese
'
' Inputs:Name of the query
User must have permission on “MSysQueries” and “MSysObjects” Else grant permission To Admin and other user from Tools-> Security-> User and Group Permissions
'
' Returns:SQL text of the query (not the
'     results), SQL Statements
'
' Assumes:Used to view the SQL syntax in
'     side a Ms-Access query
'
'This code is copyrighted and has' limited warranties.Please see http://w
'     ww.Planet-Source-Code.com/vb/scripts/Sho
'     wCode.asp?txtCodeId=70936&lngWId=1'for details.'**************************************

'Author: Joseph Varghese
'Email: josephvarghese78@hotmail.com
'If any bugs/ suggestions found pls info
'     rm me too
'so that I can do the same in my library
'     


Private Function export_access_query_text(sDBName As String, sQueryName As String) As String

Dim objDB As New DBSession Dim sSQL As String Dim sFieldList As String Dim sWhereCond As String Dim sFromList As String Dim sGroupBy As String Dim sOrderBy As String Dim sTransform As String Dim sPivot As String Dim iFlag As Integer Dim bTransform As Boolean iFlag = 0 objDB.Connect MsAccess, sDBName objDB.ExecuteQuery "SELECT Q.ATTRIBUTE, Q.EXPRESSION, Q.FLAG, Q.LVEXTRA, Q.NAME1, " & _ "Q.NAME2, O.NAME AS [OBJECT NAME], Q.ORDER FROM MSYSOBJECTS AS O, MSYSQUERIES AS Q " & _ "WHERE O.ID=Q.OBJECTID AND O.NAME='" & sQueryName & "'" While objDB.dbRecordSet.EOF = False Select Case objDB.dbRecordSet("Attribute") Case 1: bTransform = True: iFlag = 2 Case 6: If bTransform = True Then sTransform = "TRANSFORM " & objDB.dbRecordSet("Expression") & IIf(Len(objDB.dbRecordSet("Name1")) > 0, " AS [" & objDB.dbRecordSet("Name1") & "] ", " ") bTransform = False Else If objDB.dbRecordSet("Flag") = iFlag Then sFieldList = sFieldList & objDB.dbRecordSet("Expression") & IIf(Len(objDB.dbRecordSet("Name1")) > 0, " AS [" & objDB.dbRecordSet("Name1") & "], ", ", ") End If
End If
Case 5: sFromList = sFromList & objDB.dbRecordSet("Name1") & IIf(Len(objDB.dbRecordSet("Name2")) > 0, " " & objDB.dbRecordSet("Name2") & ", ", " ") Case 8: sWhereCond = objDB.dbRecordSet("Expression") Case 9: If objDB.dbRecordSet("Flag") = iFlag Then sGroupBy = sGroupBy & objDB.dbRecordSet("Expression") & ", " Else sPivot = " PIVOT " & objDB.dbRecordSet("Expression") End If
Case 11: sOrderBy = sOrderBy & objDB.dbRecordSet("Expression") & IIf(objDB.dbRecordSet("Name1") = "d", " DESC, ", ", ") End Select
objDB.dbRecordSet.MoveNext Wend
If Len(sFieldList) > 0 And Right(Trim(sFieldList), 1) = "," Then sFieldList = Trim(Left(Trim(sFieldList), Len(Trim(sFieldList)) - 1)) If Len(sFromList) > 0 And Right(Trim(sFromList), 1) = "," Then sFromList = Trim(Left(Trim(sFromList), Len(Trim(sFromList)) - 1)) If Len(sGroupBy) > 0 And Right(Trim(sGroupBy), 1) = "," Then sGroupBy = Trim(Left(Trim(sGroupBy), Len(Trim(sGroupBy)) - 1)) If Len(sOrderBy) > 0 And Right(Trim(sOrderBy), 1) = "," Then sOrderBy = Trim(Left(Trim(sOrderBy), Len(Trim(sOrderBy)) - 1)) sSQL = sTransform & "SELECT " & Trim(sFieldList) & " FROM " & Trim(sFromList) & IIf(Len(sWhereCond) > 0, " WHERE " & Trim(sWhereCond), "") & IIf(Len(sGroupBy) > 0, " GROUP BY " & Trim(sGroupBy), "") & IIf(Len(sOrderBy) > 0, " ORDER BY " & Trim(sOrderBy), "") & sPivot export_access_query_text = sSQL objDB.DisConnect Set objDB = Nothing End Function
'usage 'txtSQLText = export_access_query_text(" ' D:\db.mdb", "MS")


Other 7 submission(s) by this author

 

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
8/11/2008 8:05:52 AMNorm Cook

This code will not compile. Is this ADO, DAO? What references are set? i. e. what is a DBSession? Also, where is MSAccess defined?
(If this comment was disrespectful, please report it.)

 
8/15/2008 5:51:58 PMJoseph Varghese

Hi,
Norm Cook, thatz a custom lbrary very sorry I forgot to inform abt that this is ADO. I will update the code using standatd methods so no will else will face the problem.
(If this comment was disrespectful, please report it.)

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
To post feedback, first please login.


 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Games | Feedback | Customize | Visual Basic Home | Site Home | Other Sites | Open Letter from Moderators | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997-2010 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.   Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.