Pages

Monday, December 26, 2011

Get Names of all the Queries Existing in a Database and Add them to a New Table Using Query

If you want to know the find the names of all queries existing in the database and add them to new table.

Here is the code-

Sub create_a_new_table_and_add_all_query_names_using_query()
' add all query names existing in a databse to a new table called qrynames
DoCmd.SetWarnings (False)
Dim qry As DAO.QueryDef
Dim stra As String
On Error Resume Next
'close the table qrynames if open
DoCmd.Close acTable, "qrynames", acSaveYes
' delete table qrynames if exists
On Error Resume Next
DoCmd.RunSQL "drop TABLE qrynames "
' create table with all queryies name qrynames
DoCmd.RunSQL "CREATE TABLE qrynames (QRY_Name Text)"
' adding query names in to tblnames
For Each qry In CurrentDb.QueryDefs
If Left(qry.Name, 1) <> "~" Then
stra = "INSERT INTO qrynames ([QRY_Name]) values(' " & qry.Name & "')"
DoCmd.RunSQL stra
End If
Next
DoCmd.SetWarnings (True)
End Sub


Download Access Database

No comments:

Post a Comment