vba - 访问 VBA 以打开/激活数据库表
问题描述
我有一个开放的 MS Access 数据库,左侧显示了 20 个表,并且打开了两个选项卡,显示了两个表的内容。我正在尝试将 vba 代码编写为 1)选择/激活已打开的选项卡之一,以及 2)为左侧尚未打开的表之一打开一个新选项卡。
我看过很多示例,但它们都在谈论表单,而不是我想在主 Access 表显示中使用的选项卡控件/选项卡。到目前为止,这是我的代码 - 我可以获得表的名称,但我不知道如何在 Access 显示中打开和激活表的选项卡。
Sub ActivateCommandsTable()
' activate or open a tab for the Commands table
Dim tbl As AccessObject, db As Object
Set db = Application.CurrentData
' Search for open AccessObject objects in AllTables collection.
For Each tbl In db.AllTables
If tbl.IsLoaded = True Then
' Print name of the table
Debug.Print tbl.name
If tbl.name = "Commands" Then
' I need some code here to activate/open the table tab
Exit Sub
End If
End If
Next tbl
End Sub
解决方案
只需使用DoCmd.OpenTable
.
DoCmd.OpenTable tbl.Name
推荐阅读
- discord.js - 无法使用 member.roles.add (id) 分配角色
- postgresql - 无法将 pgAdmin4 与 ElephantSQL 连接
- ruby-on-rails - Devis 注销错误 ActionController::InvalidAuthenticityTokenon 注销
- python - 在 apache 上运行烧瓶
- visual-studio-code - 保存在 vscode 中时自动应用更改
- makefile - 如何在内核构建makefile中将特定目标文件与c文件链接?
- file - M-< 和 M-> 在 emacs 中不能正常工作
- css - 纯 CSS 同级选择器
- java - 无法授权 Microsoft Graph API 的凭据
- node.js - 无法在快递上获得 POST 请求