简体   繁体   中英

VBA question: debug.print displays the correct data - how to get it out of Immediate window?

In my database I have certain tables that have confidential information. Each of these tables contains an empty field called "ThisTableIsConfidential". I have a function that correctly displays a list of the tables that have this field in the Immediate window. Now I want to display the list on a form and I can't figure out how to do it. I thought to put the function in a query and display that in a listbox but the query didn't work. Any ideas?

This is the function (I cobbled it together from a few different online sources):

Function GetConfidentialTable()
 Dim db As Database, tbl As TableDef, fld As Field, currentTable As String
   Set db = CurrentDb

   For Each tbl In db.TableDefs
        If (tbl.Attributes = 0) Then  

        currentTable = tbl.Name

        If FieldExists(currentTable, "ThisTableIsConfidential") = True Then
            Debug.Print currentTable
        End If
     End If

   Next tbl
End Function

You can set the listbox row source type to Value List and then use your function to return a list:

Function GetConfidentialTable()
 Dim db As Database, tbl As TableDef, fld As Field, currentTable As String
   Set db = CurrentDb

   For Each tbl In db.TableDefs
        If (tbl.Attributes = 0) Then  

        currentTable = tbl.Name

        If FieldExists(currentTable, "ThisTableIsConfidential") = True Then
            sList = sList & ";" & currentTable
        End If
     End If

   Next tbl

   GetConfidentialTable = Mid(sList,2)
End Function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM