代码的一部分
dim oMainForm as object
dim oColumnList as object
dim theValue as variant
oMainForm = ThisDatabaseDocument.FormDocuments.getByName("update_rform")
oColumnList = oMainForm.getByName("rid") #rid is the name of the field from which I need to get the value
theValue=oColumnList.getCurrentValue()
rid=theValue
当我运行宏时,运行时错误弹出
找不到
属性或方法: getByName
我一整天都在寻找解决方案。我遇到了一些建议,比如连接到xray工具或加载access2base库,但我做不到。但我不知道,为什么这是一项如此困难的任务。
我对LibreOffice Basic编程和一般的数据库都是新手。
发布于 2018-06-12 05:29:35
下面的代码只获取表单文档定义,而不是一个打开的表单,如https://ask.libreoffice.org/en/question/63260/how-to-access-to-the-controls-of-a-base-form-with-basic/?answer=63280#post-id-63280所述。
ThisDatabaseDocument.FormDocuments.getByName()
正确的解决方案取决于如何调用宏。例如,在打开任何表单之前,可以从主Base屏幕调用以下代码。代码的一部分来自https://ask.libreoffice.org/en/question/7555/open-form-via-macro-in-libreoffice-base/。
Sub getFormVal
form_container = ThisDatabaseDocument.FormDocuments.getByName("update_rform")
form_container.open()
Wait 500
oMainForm = form_container.Component.getDrawPage().getForms().getByIndex(0)
oControl = oMainForm.getByName("rid")
theValue = oControl.getCurrentValue()
MsgBox theValue
End Sub
要使ThisDatabaseDocument
正常工作,代码必须在文档中,而不是在My Macros下,如https://ask.libreoffice.org/en/question/94670/thisdatabasedocument-vs-thiscomponent/中所述。
一种比从控件获取值更优雅的方法是从窗体记录集中读取列,如https://stackoverflow.com/a/39770933/5100564中所述
但我不知道
,为什么这是一项如此困难的任务。
无论如何,数据库可能很难使用,而且学习编写LibreOffice基宏是出了名的困难。然而,只要付出足够的努力,Base就能让许多事情成为可能。
我遇到了一些建议,比如连接xray工具。
是的,在开发LibreOffice宏时,像XrayTool或MRI这样的内省工具是必不可少的。
https://stackoverflow.com/questions/50802571
复制相似问题