VBA MS访问 - 运行时错误3129“操作无效/允许”
因此,我在“ SET EXO_MODEL ....”上收到该错误消息。我要做的就是说,如果该表中的该字段具有X值,那么……但是我认为我缺少一些非常基本的东西。
因此,我希望我设定的变量存储每个字段的下一个值以获取未来条目。然后,执行条件以定义每种情况的SPT的默认值。
Option Compare Database
'------------------------------------------------------------
' Macro1
'
'------------------------------------------------------------
Sub Command1_Click()
Dim tdf As TableDef
Dim db As DAO.Database
Set db = CurrentDb()
Set tdf = db.TableDefs("Table Special procurement type")
Set EXO_Model = tdf.Fields("Drop List").Value '<------Error
Set Material_Type = tdf.Fields("Material Type").Value
Set Plant_of_Origin = tdf.Fields("Plant of Origin").Value
SPT = tdf.Fields("Special procurement type").DefaultValue
If EXO_Model = "TOLLING - FG" Then
SPT = 30
ElseIf EXO_Model = "TURNKEY - FG" Then
SPT = ""
ElseIf EXO_Model = "TURNKEY - LL" Then
SPT = "\"
ElseIf EXO_Model = "TOLLING - LL" And Plant_of_Origin = "004 - BleBle" Then
SPT = "L2"
ElseIf EXO_Model = "TOLLING - LL" And Plant_of_Origin = "007 - BlaBla" Then
SPT = "C2"
End If
End Sub
so I am getting that error message at "Set EXO_Model....". What I am trying to do is say that if that field from that table has X value, then...... But I think I am missing something very basic.
So I would like the variables that I have set to store the hypotetical next value of each field for future entries. Then, performe the conditional to define the default value of SPT for each situation.
Option Compare Database
'------------------------------------------------------------
' Macro1
'
'------------------------------------------------------------
Sub Command1_Click()
Dim tdf As TableDef
Dim db As DAO.Database
Set db = CurrentDb()
Set tdf = db.TableDefs("Table Special procurement type")
Set EXO_Model = tdf.Fields("Drop List").Value '<------Error
Set Material_Type = tdf.Fields("Material Type").Value
Set Plant_of_Origin = tdf.Fields("Plant of Origin").Value
SPT = tdf.Fields("Special procurement type").DefaultValue
If EXO_Model = "TOLLING - FG" Then
SPT = 30
ElseIf EXO_Model = "TURNKEY - FG" Then
SPT = ""
ElseIf EXO_Model = "TURNKEY - LL" Then
SPT = "\"
ElseIf EXO_Model = "TOLLING - LL" And Plant_of_Origin = "004 - BleBle" Then
SPT = "L2"
ElseIf EXO_Model = "TOLLING - LL" And Plant_of_Origin = "007 - BlaBla" Then
SPT = "C2"
End If
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TableDef字段没有值,它们代表列的定义。
要读取值,请打开一个记录集。
如果是形式,您将获得当前记录的值:
好的,我开始理解您要做的事情。
您无法定义这样的默认值。
您可以在
spt_gotfocus()
事件中以表单代码进行此操作。如图所示,读取其他字段的值,计算代码中的默认值,然后设置spt.value
。TableDef fields don't have values, they represent the definition of the column.
To read values, you open a Recordset.
If this is in a form, you get the values of the current record like this:
Ok, I start to understand what you are trying to do.
You can't define default values like this.
You can do this in the form code, in the
SPT_GotFocus()
event. Read the values of the other fields as shown, calculate the default value as you have in your code, then setSPT.Value
.