vba 突然“编译错误:未找到方法或数据成员”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18698496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 23:13:47  来源:igfitidea点击:

Sudden "Compile error: method or data member not found"

vbams-accessaccess-vbams-access-2010

提问by candyA

Can anyone tell me why all of a sudden my 2010 Access database is not recognizing a key field in one of my tables? VBA recognizes every other field defined in the table? I've double and triple checked that everything is spelled correctly.

谁能告诉我为什么我的 2010 Access 数据库突然无法识别我的一个表中的关键字段?VBA 识别表中定义的所有其他字段?我已经两次和三次检查所有内容是否拼写正确。

Code where compile error appears:

出现编译错误的代码:

Me.benefitID = Nz(DMax("benefitID", "tblBenefits"), 0) + 1

tblBenefits fields:

tblBenefits 字段:

benefitID (Primary key)
benefitAnimalWelfare
benefitSafety
benefitCostSavings
benefitImprovedPractice
benefitAdministrative
benefitOther

Entire code:

完整代码:

Private Sub NewIdeaButton_Click()
On Error GoTo NewIdeaButton_Click_Err

    'new idea boolean is true
    newIdea = True

    On Error Resume Next
    DoCmd.GoToRecord , "", acNewRec
    'assign IDs for ideaID, benefitID, statusID 
    Me.ideaID = Nz(DMax("ideaID", "tblIdeaDetails"), 0) + 1
    Me.benefitID = Nz(DMax("benefitID", "tblBenefits"), 0) + 1
    Me.statusID = Nz(DMax("statusID", "tblStatus"), 0) + 1

    Me.PrintIdeaButton.Visible = False
    Me.DeleteIdeaButton.Visible = False
    Me.IdeaStatusFormButton.Visible = False
    Me.CancelButton.Visible = True
    Me.ClearListBoxButton.Visible = False
    Me.AttachedLabel.Visible = False
    Me.FileList.Visible = False
    Me.FileList.RowSourceType = "Value List"

    Me.ideaSubmitter.SetFocus
    If (MacroError <> 0) Then
        Beep
        MsgBox MacroError.Description, vbOKOnly, ""
    End If

NewIdeaButton_Click_Exit:
    Me.NewIdeaButton.Visible = False
    Exit Sub

NewIdeaButton_Click_Err:
    MsgBox Error$
    Resume NewIdeaButton_Click_Exit

End Sub

I've tried selecting the Microsoft DAO 3.6 Object Library Reference, but I receive a "Name conflicts with existing module, project, or object library". I read that if you deselect the Microsoft Office 14.0 Object Library, it'll take care of that error. But I don't think this is something I want to deselect?

我已尝试选择 Microsoft DAO 3.6 对象库参考,但收到“名称与现有模块、项目或对象库冲突”。我读到如果您取消选择 Microsoft Office 14.0 对象库,它将处理该错误。但我不认为这是我想取消选择的东西?

I've also tried deleting the relationship between this table and another, renaming the field, resetting the primary key to a different field, it still won't recognize this field.

我也试过删除这个表和另一个表之间的关系,重命名字段,将主键重置为不同的字段,它仍然无法识别这个字段。

Also tried a compact and repair database, but got the message "The compact and repair operation has been canceled. You might not have adequate permissions to the folder that the database is located in. You need full permission to the directory the database is located to compact and repair. Contact your system administrator for more information." I've been able to run a C & R in the past?

还尝试了压缩和修复数据库,但收到消息“压缩和修复操作已被取消。您可能对数据库所在的文件夹没有足够的权限。您需要对数据库所在目录的完全权限压缩和修复。有关详细信息,请联系您的系统管理员。” 我过去可以运行 C&R 吗?

回答by ThunderFrame

Access caches the field names as WithEventsAccessFieldobjects within the form/report at the time you assignthe form/report's Record Source property. That means that changes to your table or query are not propagated to the Form/Report unlessyou explicitly reassign the Record Source property, thereby forcing a refresh of the cached fields.

WithEventsAccessField在您分配窗体/报表的记录源属性时,Access 将字段名称缓存为窗体/报表中的对象。这意味着对表或查询的更改不会传播到表单/报表,除非您明确重新分配记录源属性,从而强制刷新缓存的字段。

If you've previously used a benefitIDas a member of the Form/Report, but the cache no longer includes that field name (even if the Record Source does contain the field name), then you'll need to update the RecordSource property for the cache to refresh and the code to compile.

如果您之前已将 abenefitID作为表单/报表的成员,但缓存不再包含该字段名称(即使记录源确实包含该字段名称),则您需要更新该字段的 RecordSource 属性缓存刷新和代码编译。

If the name of the benefitIDfield has changed in the RecordSource, then you'll still need to refresh the RecordSource, but you'll also need to update the references to benefitIDso that they use the new field name.

如果benefitIDRecordSource中的字段名称已更改,则您仍需要刷新 RecordSource,但您还需要更新对的引用,benefitID以便它们使用新的字段名称。

回答by Eddy Jawed

Exclamations points !worked for me. I replaced the periods .with them wherever I found this error.

感叹号!对我有用。.在发现此错误的任何地方,我都用它们替换了句点。

回答by LiamH

I have just come across the very same issue. I found that the exclamation mark that I usually use no longer does. So, I have had to use .value, e.g.:

我刚刚遇到了同样的问题。我发现我通常使用的感叹号不再使用了。所以,我不得不使用.value,例如:

me.benefitID.value

This appears to have fixed my issue, but I am still confused about the conflicting references.

这似乎解决了我的问题,但我仍然对相互矛盾的引用感到困惑。