Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access VBA问题:debug.print显示正确的数据-如何将其从即时窗口中取出?_Ms Access_Vba - Fatal编程技术网

Ms access VBA问题:debug.print显示正确的数据-如何将其从即时窗口中取出?

Ms access VBA问题:debug.print显示正确的数据-如何将其从即时窗口中取出?,ms-access,vba,Ms Access,Vba,在我的数据库中,我有一些包含机密信息的表。这些表中的每个表都包含一个名为“ThisTablesConfig”的空字段。我有一个函数,可以在即时窗口中正确显示包含此字段的表的列表。现在我想在表单上显示列表,但我不知道该怎么做。我本想把这个函数放在一个查询中,然后在一个列表框中显示出来,但这个查询不起作用。有什么想法吗 这就是功能(我从几个不同的在线来源拼凑而成): 您可以将listbox行源类型设置为值列表,然后使用函数返回列表: Function GetConfidentialTable()

在我的数据库中,我有一些包含机密信息的表。这些表中的每个表都包含一个名为“ThisTablesConfig”的空字段。我有一个函数,可以在即时窗口中正确显示包含此字段的表的列表。现在我想在表单上显示列表,但我不知道该怎么做。我本想把这个函数放在一个查询中,然后在一个列表框中显示出来,但这个查询不起作用。有什么想法吗

这就是功能(我从几个不同的在线来源拼凑而成):


您可以将listbox行源类型设置为值列表,然后使用函数返回列表:

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

就这样,谢谢你!我不得不对你的答案稍加修改如下:1。我将sList更改为:sList=sList¤tTable&vbCrLf以添加换行符,使其显示为列表而不是长字符串。2.一旦我这样做了,访问要求元素是一个文本框来显示整个内容,而不是一个列表框(只显示第一行)。3.这也意味着我可以将getSecretentialTable=Mid(sList,2)更改为getSecretentialTable=sList谢谢@塔拉,如果这是适合你的,但我不认为这是一个长期的好主意。没有必要更改代码或使用文本框。我想您一定错过了我的评论,即如果您对列表框进行了任何其他更改(例如设置列数),您必须将行源类型设置为值列表(列表框的属性表)?我已经测试了上述内容,它可以在一个新的列表框上工作,只需更改行源类型的设置。这是一件不同寻常的事情,而且这种方法是标准的。@Remou的代码生成一个适当的字符串,作为一个列表框的值列表,该列表框的格式为单列。
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