VBA MS访问 - 运行时错误3129“操作无效/允许”

发布于 2025-02-13 07:29:18 字数 1087 浏览 0 评论 0原文

因此,我在“ 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无语# 2025-02-20 07:29:18

TableDef字段没有值,它们代表列的定义。

要读取值,请打开一个记录集

如果是形式,您将获得当前记录的值:

EXO_Model = Me("Drop List").Value

好的,我开始理解您要做的事情。
您无法定义这样的默认值。

您可以在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:

EXO_Model = Me("Drop List").Value

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 set SPT.Value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文