'----------------------------------------------------------------
' Hands-On 15-1
'----------------------------------------------------------------

Sub Create_SelectQuery_DAO()
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim strSQL As String
    
    On Error GoTo Err_SelectQuery
    
    strSQL = "SELECT * FROM Employees "
    strSQL = strSQL & "WHERE TitleOfCourtesy = 'Ms.'"
    Set db = OpenDatabase("C:\Acc07_ByExample\Northwind.mdb")
    Set qdf = db.CreateQueryDef("myQuery", strSQL)
ExitHere:
    Set qdf = Nothing
    db.Close
    Set db = Nothing
    Exit Sub
Err_SelectQuery:
    If Err.Number = 3012 Then
        MsgBox "Query with this name already exists."
    Else
        MsgBox Err.Description
    End If
    Resume ExitHere
End Sub


'----------------------------------------------------------------
' Hands-On 15-2
'----------------------------------------------------------------

Sub Create_SelectQuery_ADO()
   Dim cat As ADOX.Catalog
   Dim cmd As ADODB.Command
   Dim strPath As String
   Dim strSQL As String
   Dim strQryName As String

   On Error GoTo ErrorHandler

   ' assign values to string variables
   strPath = CurrentProject.Path & "\Northwind 2007.accdb"
   strSQL = "SELECT Employees.* FROM Employees WHERE " _
      & "Employees.City='Redmond';"

   strQryName = "Redmond Employees"

   ' open the Catalog
   Set cat = New ADOX.Catalog
   cat.ActiveConnection = _
      "Provider=Microsoft.ACE.OLEDB.12.0;" & _
      "Data Source=" & strPath

   ' create a query based on the specified
   ' SELECT statement
   Set cmd = New ADODB.Command
   cmd.CommandText = strSQL

   ' add the new query to the database
   cat.Views.Append strQryName, cmd
   
   MsgBox "The procedure completed successfully.", _
       vbInformation, "Create Select Query"
ExitHere:
   Set cmd = Nothing
   Set cat = Nothing
   Exit Sub

ErrorHandler:
   If InStr(Err.Description, "already exists") Then
      cat.Views.Delete strQryName
      Resume
   Else
      MsgBox Err.Number & ": " & Err.Description
      Resume ExitHere
   End If
End Sub


'----------------------------------------------------------------
' Hands-On 15-3
'----------------------------------------------------------------

Sub Execute_SelectQuery_ADO()
   Dim cmd As ADODB.Command
   Dim rst As ADODB.Recordset
   Dim strPath As String

   strPath = CurrentProject.Path & "\Northwind.mdb"

   Set cmd = New ADODB.Command
   With cmd
      .ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
          "Data Source=" & strPath
      .CommandText = "[Products by Category]"
      .CommandType = adCmdTable
   End With

   Set rst = New ADODB.Recordset
   Set rst = cmd.Execute

   Debug.Print rst.GetString

   rst.Close
   Set rst = Nothing
   Set cmd = Nothing
   MsgBox "View results in the Immediate Window."
End Sub


'----------------------------------------------------------------
' Hands-On 15-4
'----------------------------------------------------------------

Sub Execute_SelectQuery2_ADO()
   Dim cat As ADOX.Catalog
   Dim cmd As ADODB.Command
   Dim rst As ADODB.Recordset
   Dim strPath As String

   strPath = CurrentProject.Path & "\Northwind.mdb"

   Set cat = New ADOX.Catalog
   cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=" & strPath

   Set cmd = New ADODB.Command
   Set cmd = cat.Views("Products by Category").Command

   Set rst = New ADODB.Recordset
   rst.Open cmd, , adOpenStatic, adLockReadOnly, adCmdTable

   Debug.Print rst.GetString
   MsgBox "The query returned " & rst.RecordCount & vbCr & _
      " records to the Immediate Window."
   rst.Close
   Set rst = Nothing
   Set cmd = Nothing
   Set cat = Nothing
End Sub


'----------------------------------------------------------------
' Hands-On 15-5
'----------------------------------------------------------------

Sub Modify_Query_ADO()
   Dim cat As ADOX.Catalog
   Dim cmd As ADODB.Command
   Dim strPath As String
   Dim newStrSQL As String
   Dim oldStrSQL As String
   Dim strQryName As String

   strPath = CurrentProject.Path & "\Northwind 2007.accdb"
   
   newStrSQL = "SELECT Employees.* FROM Employees" & _
      " WHERE Employees.City='Redmond'" & _
      " ORDER BY [Last Name];"
   
   strQryName = "Redmond Employees"

   Set cat = New ADOX.Catalog
   cat.ActiveConnection = _
      "Provider=Microsoft.ACE.OLEDB.12.0;" & _
      "Data Source=" & strPath

   Set cmd = New ADODB.Command
   Set cmd = cat.Views(strQryName).Command

   ' get the existing SQL statement for this query
   oldStrSQL = cmd.CommandText

   MsgBox oldStrSQL, vbInformation, _
      "Current SQL Statement"

   ' now update the query's SQL statement
   cmd.CommandText = newStrSQL
   MsgBox newStrSQL, vbInformation, _
      "New SQL Statement"

   ' save the modified query
   Set cat.Views(strQryName).Command = cmd

   Set cmd = Nothing
   Set cat = Nothing
End Sub


'----------------------------------------------------------------
' Hands-On 15-6
'----------------------------------------------------------------

Sub CreateRun_ParameterQuery_DAO()
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim rst As DAO.Recordset
    Dim strQryName As String
    Dim strSQL As String
    
    On Error GoTo Err_Handler
    
    strQryName = "myParamQuery"
    strSQL = "PARAMETERS [Enter Country] Text; " & _
    "SELECT * FROM Customers WHERE Country = [Enter Country];"
    
    Set db = OpenDatabase("C:\Acc07_ByExample\Northwind.mdb")
    Set qdf = db.CreateQueryDef(strQryName, strSQL)
    
RunQuery:
    'specify the parameter
   qdf.Parameters("Enter Country") = _
        InputBox("Enter the country name:", _
        "Which Country?", "Germany")
        
   If IsNull(qdf.Parameters("Enter Country").Value) _
        Then GoTo ExitHere
 
    'open a recordset based on the specified query
    Set rst = qdf.OpenRecordset(dbOpenDynaset)
    rst.MoveLast
    MsgBox "Number of records: " & rst.RecordCount
    
    'write the contents of the second field
    'to the Immediate Window
    rst.MoveFirst
    Do Until rst.EOF
        Debug.Print rst(1)
        rst.MoveNext
    Loop

ExitHere:
    If Not rst Is Nothing Then
        rst.Close
        Set rst = Nothing
    End If
    Set qdf = Nothing
    db.Close
    Set db = Nothing
    Exit Sub
    
Err_Handler:
    If Err.Number = 3012 Then
        MsgBox "This query already exists."
        Set qdf = db.QueryDefs(strQryName)
        Resume RunQuery
    Else
        MsgBox Err.Description
    End If
    Resume ExitHere
End Sub


'----------------------------------------------------------------
' Hands-On 15-7
'----------------------------------------------------------------

Sub Create_ParameterQuery_ADO()
   Dim cat As ADOX.Catalog
   Dim cmd As ADODB.Command
   Dim strPath As String
   Dim strSQL As String
   Dim strQryName As String

   On Error GoTo ErrorHandler

   strPath = CurrentProject.Path & "\Northwind.mdb"

   strSQL = "Parameters [Country Name] Text;" & _
      "SELECT Customers.* FROM Customers WHERE " _
      & "Customers.Country=[Country Name];"

   strQryName = "Customers by Country"

   Set cat = New ADOX.Catalog
   cat.ActiveConnection = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & strPath

   Set cmd = New ADODB.Command
   cmd.CommandText = strSQL

   cat.Procedures.Append strQryName, cmd
   Set cmd = Nothing
   Set cat = Nothing

   MsgBox "The procedure completed successfully.", _
      vbInformation, "Create Parameter Query"
   Exit Sub

ErrorHandler:
   If InStr(Err.Description, "already exists") Then
      cat.Procedures.Delete strQryName
      Resume
   Else
      MsgBox Err.Number & ": " & Err.Description
   End If
End Sub


'----------------------------------------------------------------
' Hands-On 15-8
'----------------------------------------------------------------

Sub Execute_ParamQuery_ADO(strCountry As String)
   Dim cat As ADOX.Catalog
   Dim cmd As ADODB.Command
   Dim rst As ADODB.Recordset
   Dim strQryName As String
   Dim strPath As String

   strQryName = "Customers by Country"
   strPath = CurrentProject.Path & "\Northwind.mdb"

   Set cat = New ADOX.Catalog
   cat.ActiveConnection = _
      "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=" & strPath

   Set cmd = New ADODB.Command
   Set cmd = cat.Procedures(strQryName).Command

   ' specify a parameter value
   cmd.Parameters("[Country Name]") = strCountry
   
   ' use the Execute method of the Command
   ' object to open the recordset
   Set rst = cmd.Execute
     
   ' return company names to the Immediate Window
   Do Until rst.EOF
      Debug.Print rst(1)
      rst.MoveNext
   Loop

   rst.Close
   Set rst = Nothing
   Set cmd = Nothing
   Set cat = Nothing
End Sub


'----------------------------------------------------------------
' Hands-On 15-9
'----------------------------------------------------------------

Sub MakeATableQuery_DAO()
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim strSQL As String
    
    On Error GoTo Err_Handler
    
    strSQL = "SELECT * INTO SouthAmericanClients " & _
             "FROM Customers WHERE Country='Brazil';"
    Set db = OpenDatabase("C:\Acc07_ByExample\Northwind.mdb")
    Set qdf = db.CreateQueryDef("", strSQL)
    qdf.Execute
ExitHere:
    Set qdf = Nothing
    db.Close
    Set db = Nothing
    Exit Sub
Err_Handler:
    MsgBox Err.Description
    Resume ExitHere
End Sub


'----------------------------------------------------------------
' Hands-On 15-10
'----------------------------------------------------------------

Sub CreateRunUpdateQuery_DAO()
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim strSQL As String
    
    On Error GoTo Err_Handler
    
    strSQL = "UPDATE Suppliers INNER JOIN Products ON " & _
    "Suppliers.SupplierID = Products.SupplierID " & _
    "SET Products.UnitPrice = [UnitPrice]+2 " & _
    "WHERE (((Suppliers.CompanyName)='Tokyo Traders'));"
    Set db = OpenDatabase("C:\Acc07_ByExample\Northwind.mdb")
    
    Set qdf = db.CreateQueryDef("PriceIncrease", strSQL)
    qdf.Execute
ExitHere:
    Set db = Nothing
    Exit Sub
Err_Handler:
    If Err.Number = 3012 Then
        MsgBox "Query with this name already exists."
    Else
        MsgBox Err.Description
    End If
    Resume ExitHere
End Sub


Sub UpdateRun_DAO()
    Dim db As DAO.Database
    Set db = OpenDatabase("C:\Acc07_ByExample\Northwind.mdb")
    db.Execute "PriceIncrease"
    db.Close
    Set db = Nothing
End Sub


'----------------------------------------------------------------
' Hands-On 15-11
'----------------------------------------------------------------

Sub Execute_UpdateQuery_ADO()
   Dim conn As ADODB.Connection
   Dim NumOfRec As Integer
   Dim strPath As String

   strPath = CurrentProject.Path & "\Northwind.mdb"

   Set conn = New ADODB.Connection

   conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=" & strPath

   conn.Execute "UPDATE Products " & _
      "SET UnitPrice = UnitPrice + 1" & _
      " WHERE CategoryId = 8", _
      NumOfRec, adExecuteNoRecords

   MsgBox NumOfRec & " records were updated."
   conn.Close
   Set conn = Nothing
End Sub


'----------------------------------------------------------------
' Hands-On 15-12
'----------------------------------------------------------------

Sub Execute_UpdateQuery2_ADO()
   Dim cmd As ADODB.Command
   Dim NumOfRec As Integer
   Dim strPath As String

   strPath = CurrentProject.Path & "\Northwind.mdb"

   Set cmd = New ADODB.Command
   With cmd
      .ActiveConnection = _
            "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=" & strPath
      .CommandText = "Update Products " & _
            "Set UnitPrice = UnitPrice *1.1"
      .Execute NumOfRec, adExecuteNoRecords
   End With
   MsgBox NumOfRec
   Set cmd = Nothing
End Sub


'----------------------------------------------------------------
' Hands-On 15-13
'----------------------------------------------------------------

Sub RunAppendQry_DAO()
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim strSQL As String
    
    strSQL = "SELECT * FROM SouthAmericanClients " & _
               "WHERE Country = 'Argentina'"
    Set db = OpenDatabase("C:\Acc07_ByExample\Northwind.mdb")
    Set rst = db.OpenRecordset(strSQL, dbOpenSnapshot)
    
    If rst.EOF Or rst.BOF Then
        ' Argentina clients not found in destination
        ' table - proceed with insert
        db.Execute "INSERT INTO SouthAmericanClients " & _
                   "SELECT * FROM Customers " & _
                   "WHERE Country = 'Argentina'"
        
        MsgBox "Argentina clients have been appended."
    Else
        MsgBox "Clients from Argentina already exist " & _
            "in the destination table."
    End If
    
    rst.Close
    Set rst = Nothing
    db.Close
    Set db = Nothing
End Sub


'----------------------------------------------------------------
' Code on page 374
'----------------------------------------------------------------

Sub RunAppendQry_ADO()
    Dim conn As ADODB.Connection
    Dim strSQL As String
    Dim recAffected As Long
    
    On Error Resume Next

    Set conn = New ADODB.Connection
    
    conn.Provider = "Microsoft.Jet.OLEDB.4.0"
    conn.Open "C:\Acc07_ByExample\Northwind.mdb"
    strSQL = "INSERT INTO SouthAmericanClients " & _
                       "SELECT * FROM Customers " & _
                       "WHERE Country = 'Venezuela'"
    
    conn.Execute strSQL, recAffected
    
    If Err <> 0 Then
        Debug.Print "Error Number: " & Err.Number
        Debug.Print "Error Description: " & Err.Description
    Else
        Debug.Print recAffected & " records were inserted."
    End If
    conn.Close
    Set conn = Nothing
End Sub


'----------------------------------------------------------------
' Hands-On 15-14
'----------------------------------------------------------------

Sub CreateRunDeleteQuery_DAO()
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim strQryName As String
    Dim strSQL As String
    
    On Error GoTo ErrorHandler
    
    strQryName = "DeletePolishOrders"
    strSQL = "DELETE * FROM Orders WHERE [ShipCountry] = 'Poland'"
    
    Set db = OpenDatabase("C:\Acc07_ByExample\Northwind.mdb")
    Set qdf = db.CreateQueryDef(strQryName, strSQL)
    
    ' Chr(13) & Chr(13) is a double carriage return
    If (MsgBox("Do you want to perform the following: " & _
        Chr(13) & Chr(13) _
        & qdf.SQL, vbYesNo + vbDefaultButton2, _
        "SQL Expression")) = vbYes Then
    
        qdf.Execute dbFailOnError
        MsgBox qdf.RecordsAffected & _
                  " records were deleted."
    End If
ExitHere:
    Set qdf = Nothing
    db.Close
    Set db = Nothing
    Exit Sub
ErrorHandler:
    If Err.Number = 3012 Then
        Set qdf = db.QueryDefs(strQryName)
        Resume Next
    Else
        MsgBox Err.Number & ":" & Err.Description
        Resume ExitHere
    End If
End Sub


'----------------------------------------------------------------
' Code on pages 377-378
'----------------------------------------------------------------

Sub PassThruQry_DAO()
    Dim db As DAO.Database
    Dim qdfPass As DAO.QueryDef
    
    On Error GoTo err_PassThru
    
    Set db = CurrentDb
    Set qdfPass = db.CreateQueryDef("GetRecords")
    
    ' enter your own connect string
    ' suppy the server database name you
    ' want to connect to, your User ID,
    ' password, and the Data Source name
    
    qdfPass.Connect = "ODBC;Database=myDbName; " & _
        "UID=MILL;PWD=year00;DSN=myDataS"
    qdfPass.SQL = "Select * From dbo.entity"
    qdfPass.ReturnsRecords = True
    qdfPass.MaxRecords = 15
    
    DoCmd.OpenQuery "GetRecords"
    Exit Sub
err_PassThru:
    If Err.Number = 3151 Then
        MsgBox Err.Description
        Exit Sub
    End If
    db.QueryDefs.Delete "GetRecords"
    Resume 0
    Exit Sub
End Sub


Sub PassThru2()
    Dim db As DAO.Database
    Dim qdfPass As DAO.QueryDef
    Dim rstTemp As DAO.Recordset
    
    On Error GoTo err_PassThru
    
    Set db = CurrentDb
    Set qdfPass = db.CreateQueryDef("")
    
    ' enter your own connect string
    ' supply the server database name you
    ' want to connect to, your User ID,
    ' password, and the Data Source name
    
    qdfPass.Connect = "ODBC;Database=myDbName;UID=MILL;" & _
    "PWD=year00;DSN=myDataS"
    qdfPass.SQL = "SELECT * FROM dbo.entity"
    qdfPass.ReturnsRecords = True
    qdfPass.MaxRecords = 15
    
    Set rstTemp = qdfPass.OpenRecordset()
    
    ' print data from two fields to the Immediate window
    With rstTemp
        Do While Not .EOF
            Debug.Print .Fields("entity_id"), .Fields("entity_name")
            .Fields ("entity_name")
            .MoveNext
        Loop
        .Close
    End With
    SendKeys "^g"
ExitHere:
    Set db = Nothing
    Exit Sub
err_PassThru:
    MsgBox Err.Number & ":" & Err.Description
    Resume ExitHere
End Sub


'----------------------------------------------------------------
' Hands-On 15-15
'----------------------------------------------------------------

Sub Create_PassThroughQuery()
   Dim cat As ADOX.Catalog
   Dim cmd As ADODB.Command
   Dim rst As ADODB.Recordset
   Dim strPath As String
   Dim strSQL As String
   Dim strQryName As String
   Dim strODBCConnect As String

   On Error GoTo ErrorHandler

   strSQL = "SELECT Customers.* FROM Customers WHERE " _
      & "Customers.Country='France';"

   strQryName = "French Customers"

   ' modify the following string to connect
   ' to your SQL Server
   strODBCConnect = "ODBC;Driver=SQL Server;" & _
      "Server=JULITTA733\JKDESKTOP1;" & _
      "Database=Northwind;" & _
      "UID=;" & _
      "PWD="

   ' strODBCConnect = "ODBC;DSN=ODBCNorth;UID=sa;PWD=;"

   Set cat = New ADOX.Catalog
   cat.ActiveConnection = CurrentProject.Connection

   Set cmd = New ADODB.Command
   With cmd
      .ActiveConnection = cat.ActiveConnection
      .CommandText = strSQL
      .Properties("Jet OLEDB:ODBC Pass-Through Statement") = True
      .Properties("Jet OLEDB:Pass-Through Query Connect String") = _
          strODBCConnect
   End With

   cat.Procedures.Append strQryName, cmd

   Set cmd = Nothing
   Set cat = Nothing
   MsgBox "The procedure completed successfully.", _
      vbInformation, "Create Pass-Through Query"
   Exit Sub

ErrorHandler:
   If InStr(Err.Description, "already exists") Then
      cat.Procedures.Delete strQryName
      Resume
   Else
      MsgBox Err.Number & ": " & Err.Description
   End If
End Sub


'----------------------------------------------------------------
' Hands-On 15-16
'----------------------------------------------------------------

Sub Execute_PassThroughQuery_ADO()
   Dim cat As ADOX.Catalog
   Dim cmd As ADODB.Command
   Dim rst As ADODB.Recordset
   Dim strConnect As String

  ' modify the connection string to connect
  ' to your SQL Server Northwind database
   strConnect = "Provider=SQLOLEDB;" & _
      "Data Source=Julitta733\JKDesktop1;" & _
      "Initial Catalog=Northwind;" & _
      "User Id=sa;" & _
      "Password="

   Set cat = New ADOX.Catalog
   cat.ActiveConnection = CurrentProject.Connection

   Set cmd = New ADODB.Command
   Set cmd = cat.Procedures("French Customers").Command
   Set rst = cmd.Execute

   Debug.Print "--French Customers Only--" & vbCrLf _
      & rst.GetString

   Set rst = Nothing
   Set cmd = Nothing
   Set cat = Nothing
End Sub


'----------------------------------------------------------------
' Hands-On 15-17
'----------------------------------------------------------------

Sub List_QryProperties_DAO()
    Dim db As DAO.Database
    Dim prp As DAO.Property
    Dim strDBName As String

    On Error Resume Next
    
    strDBName = "C:\Acc07_ByExample\Northwind 2007.accdb"
    Set db = OpenDatabase(strDBName)
    For Each prp In db.QueryDefs("Invoice Data").Properties
        Debug.Print prp.Name & "= " & prp.Value
    Next prp
    Set db = Nothing
End Sub


'----------------------------------------------------------------
' Code on page 383
'----------------------------------------------------------------

Sub List_AllQueries_DAO()
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    
    Set db = OpenDatabase("C:\Acc07_ByExample\Northwind 2007.accdb")
    For Each qdf In db.QueryDefs
        Debug.Print qdf.Name
    Next qdf
    
    Set qdf = Nothing
    db.Close
    Set db = Nothing
End Sub


'----------------------------------------------------------------
' Hands-On 15-18
'----------------------------------------------------------------

Sub List_AllQueries_ADO()
   Dim cat As New ADOX.Catalog
   Dim v As ADOX.View
   Dim strPath As String

   strPath = CurrentProject.Path & "\Northwind.mdb"
   cat.ActiveConnection = _
        "Provider=Microsoft.Jet.OleDb.4.0;" & _
        "Data Source= " & strPath

   For Each v In cat.Views
      Debug.Print v.Name
   Next
   
   Set cat = Nothing
End Sub


'----------------------------------------------------------------
' Hands-On 15-19
'----------------------------------------------------------------

Sub DeleteAQuery_DAO()
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    
    On Error GoTo ErrorHandler
    
    Set db = OpenDatabase("C:\Acc07_ByExample\Northwind.mdb")
    db.QueryDefs.Delete "myQuery"
ExitHere:
    db.Close
    Set db = Nothing
    Exit Sub
ErrorHandler:
    MsgBox Err.Number & ": " & Err.Description
    Resume ExitHere
End Sub


'----------------------------------------------------------------
' Hands-On 15-20
'----------------------------------------------------------------


Sub DeleteAQuery_ADO()
   Dim cat As New ADOX.Catalog
   Dim strPath As String

   On Error GoTo ErrorHandler

   strPath = CurrentProject.Path & "\Northwind 2007.accdb"
   cat.ActiveConnection = _
        "Provider=Microsoft.ACE.OLEDB.12.0;" & _
        "Data Source= " & strPath

   cat.Views.Delete "Redmond Employees"

ExitHere:
   Set cat = Nothing
   Exit Sub
ErrorHandler:
   If Err.Number = 3265 Then
      MsgBox "Query does not exist."
   Else
      MsgBox Err.Number & ": " & Err.Description
   End If
   Resume ExitHere
End Sub


'----------------------------------------------------------------
' Hands-On 15-21
'----------------------------------------------------------------

Sub IsQryUpdatable_DAO()
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim fld As DAO.Field
    Dim strQryName1 As String
    Dim strQryName2 As String
    
    strQryName1 = "Order Subtotals"
    strQryName2 = "Invoices"
    
    Set db = OpenDatabase("C:\Acc07_ByExample\Northwind.mdb")
    
    Set rst = db.OpenRecordset(strQryName1)
    Debug.Print strQryName1 & _
        ": Updatable=" & rst.Updatable
    Set rst = db.OpenRecordset(strQryName2)
    Debug.Print strQryName2 & _
        ": Updatable=" & rst.Updatable
    For Each fld In rst.Fields
        If Not fld.DataUpdatable Then
            Debug.Print fld.Name & _
            " cannot be edited."
        End If
    Next
    
    rst.Close
    Set rst = Nothing
    db.Close
    Set db = Nothing
End Sub

