重命名访问 vba 中的字段 [英] Rename a field in access vba
问题描述
我需要重命名 VBA 访问代码中的字段名称以自动执行操作,使其工作得更快.我正在使用一个按钮来移动一些数据,因此需要更改列名称以进行清理.我正在使用表格进行工作,但我需要更改的表格根本没有链接到表格...
I need to rename a field name in VBA access code to automate things so it works faster. I am using a button to move some data around and need to change the column names, as a result, to clean things up. I am working out of a form but the table I need to change isn't linked to the form at all...
我尝试使用一些 VBA 代码,但不断收到变量未定义错误,例如未定义 tblFieldBookwslk50
I have tried using some VBA code but keep getting variables undefined errors like the tblFieldBookwslk50 is not defined
Set db = CurrentDb
Set rst = db.OpenRecordset("tblFieldBookwslk50", dbOpenDynaset)
'rename field names
rst.TableDefs(tblFieldBookwslk50).Fields("GDU_slk_50_Daily HU").Name =
"GDU_slk50"
rst.TableDefs(tblFieldBookwslk50).Fields("tblFieldBookwshd50_Daily HU").Name = "GDU_shd50"
db.Close
rst.Close
我希望字段名称显示为GDU_shd50"而不是tblFieldBookwshd50_Daily HU".
I want the field names to say 'GDU_shd50' rather than it say 'tblFieldBookwshd50_Daily HU'.
推荐答案
您必须使用 Database
对象中的 TableDefs
.
You have to use the TableDefs
in the Database
object.
Set db = CurrentDb
'rename field names
db.TableDefs("tblFieldBookwslk50").Fields("GDU_slk_50_Daily HU").Name = "GDU_slk50"
db.TableDefs("tblFieldBookwslk50").Fields("tblFieldBookwshd50_Daily HU").Name = "GDU_shd50"
db.Close
这篇关于重命名访问 vba 中的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!