以编程方式设置字段 'InputMask' 属性
Setting field 'InputMask' properties programmatically
我有一个Access数据库,分为前后端。
我需要以编程方式修改与 table 中的字段之一关联的 属性 的值。我确实记得几年前取得过类似的成就,但那是为了表格。
看来a的属性table只能在设计时设置;任何使用代码 (myField.Properties("InputMask").Value = "000000"
) 修改值的尝试都会导致错误。
总而言之,大约 80 个批次中有大约 40 或 50 个 table 具有必须更改的特定 类型 字段,所以我宁愿使用代码而不是手动执行此操作。有人可以建议使用 VBA 执行此操作的方法吗?
目前我已经考虑使用 CurrentDb.Execute sqlString
删除和重新创建该字段,但如果可能的话我想保留 InputMask
属性。
原始数据库是 2002/3 格式,但我在 Access 2010 中编辑它。
我使用了以下代码。它将更改指定的 Table 和 Field....
的 InputMask
Option Compare Database
Option Explicit
Sub Test_It()
Dim WGD
WGD = Resize_And_AddInputMask("Table3", "SomeNbr")
End Sub
' Modified version of code found at: http://www.tek-tips.com/viewthread.cfm?qid=1708626
Public Function Resize_And_AddInputMask(ByVal someTableName As String, ByVal someZCField As String)
Dim db As DAO.Database
Dim td As DAO.TableDef
Dim fd As DAO.Field
Dim prp As DAO.Property
Set db = CurrentDb
Set td = db.TableDefs(someTableName)
Set fd = td.Fields(someZCField)
fd.Properties("InputMask") = "000099"
fd.Properties.Refresh
db.TableDefs.Refresh
Set prp = Nothing
Set fd = Nothing
Set td = Nothing
Set db = Nothing
End Function
我有一个Access数据库,分为前后端。
我需要以编程方式修改与 table 中的字段之一关联的 属性 的值。我确实记得几年前取得过类似的成就,但那是为了表格。
看来a的属性table只能在设计时设置;任何使用代码 (myField.Properties("InputMask").Value = "000000"
) 修改值的尝试都会导致错误。
总而言之,大约 80 个批次中有大约 40 或 50 个 table 具有必须更改的特定 类型 字段,所以我宁愿使用代码而不是手动执行此操作。有人可以建议使用 VBA 执行此操作的方法吗?
目前我已经考虑使用 CurrentDb.Execute sqlString
删除和重新创建该字段,但如果可能的话我想保留 InputMask
属性。
原始数据库是 2002/3 格式,但我在 Access 2010 中编辑它。
我使用了以下代码。它将更改指定的 Table 和 Field....
的 InputMaskOption Compare Database
Option Explicit
Sub Test_It()
Dim WGD
WGD = Resize_And_AddInputMask("Table3", "SomeNbr")
End Sub
' Modified version of code found at: http://www.tek-tips.com/viewthread.cfm?qid=1708626
Public Function Resize_And_AddInputMask(ByVal someTableName As String, ByVal someZCField As String)
Dim db As DAO.Database
Dim td As DAO.TableDef
Dim fd As DAO.Field
Dim prp As DAO.Property
Set db = CurrentDb
Set td = db.TableDefs(someTableName)
Set fd = td.Fields(someZCField)
fd.Properties("InputMask") = "000099"
fd.Properties.Refresh
db.TableDefs.Refresh
Set prp = Nothing
Set fd = Nothing
Set td = Nothing
Set db = Nothing
End Function