Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fetching .SQL from a View or user defined function?

Status
Not open for further replies.

wingpeople

Programmer
Oct 18, 2002
24
US
I'm struggling with using an ADP and ADO vs. the familiar (to me) MDB and DAO. What would be the equivalent in an ADP to this MDB code that fetches the .SQL property from a QueryDef called "qryABC"? (in the ADP, it might be a View or user defined function).

Code:
Dim MyDB as Database
Dim MyQD as Querydef
Dim MySQL as String

Set MyDB = CurrentDB
Set MyQD = MyDB.Querydefs("qryABC")

MySQL = MyQD.SQL
---
I've tried using the same code (with DAO.Database, DAO.Querydef, etc), but it bombs out when I try to get at the Querydef in the current database.

I'm lost. Help!
 
Here is some code that will look at the view collection, but I don't believe you can get at the SQL. Hopefully this will give you a starting point.

Public Function testAccess()
Dim cn As New ADODB.Connection, sql1 As String
Dim rs As ADODB.Recordset

Set rs = New ADODB.Recordset

''- Reference needed.
''- Microsoft ADO Ext. 2.1 for DDL and Security
Dim cg As New ADOX.Catalog
Set cg.ActiveConnection = CurrentProject.Connection

Dim v As View
Dim vn As View
For Each v In cg.Views
Debug.Print "views = "; v.Name
Next
Set vn = cg.Views("query1")

rs.Open vn.Name, connString, adOpenForwardOnly, adLockReadOnly

Dim fl As ADODB.Field
For Each fl In rs.Fields
Debug.Print "Field Name = "; fl.Name
Debug.Print "Field Value = "; fl.Value
Next
Set rs = Nothing

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top