简体   繁体   English

有没有办法在不使用表格的情况下在 MS-Access 中创建表单?

[英]Is there a way to create a Form in MS-Access without using a table?

I want to show the results of a call to a webservice (several rows) in ms-Access.我想在 ms-Access 中显示调用 web 服务(几行)的结果。 To do this I created a form with the defaultView = 1 (= continuous form).为此,我创建了一个带有 defaultView = 1(= 连续表单)的表单。

Now I wonder if I can use show results from the webservice directly in my form.现在我想知道是否可以直接在我的表单中使用来自 web 服务的显示结果。 This means without creating a table which I then select with the recordsource-property.这意味着无需创建一个表,然后我使用 recordsource-property 选择该表。

Is there a way to show data a continuous-form in MS-Access without using a table?有没有办法在不使用表格的情况下在 MS-Access 中以连续形式显示数据?

I tried to set the recordset by myself like this:我试图像这样自己设置记录集:

Private Sub Form_Load()

  Set m_Dataset = CurrentDb.OpenRecordset("Test", RecordsetTypeEnum.dbOpenDynamic)
  Call m_Dataset.AddNew
  m_Dataset("OutOfThinAir") = "Hallo"
  Set Me.Recordset = m_Dataset

End Sub

But OpenRecordset raises the error "invalid argument".但是 OpenRecordset 会引发错误“无效参数”。

I also thought of setting the recordsource to a select statement without using a table name (In oracle this would be "Select ... from dual") but I did not find a working statement.我还想过将记录源设置为不使用表名的选择语句(在 oracle 中,这将是“选择...来自双重”),但我没有找到工作语句。 "SELECT 1 from dual;" “从双中选择 1;” does definitely not work.肯定不行。

Yes, but you'd need to use an ADODB recordset, not a DAO one.是的,但您需要使用 ADODB 记录集,而不是 DAO 记录集。

Eg例如

Dim m_Dataset As New ADODB.Recordset
m_Dataset.Fields.Append "OutOfThinAir",adVarWChar, 6, adFldUpdatable
m_Dataset.Open
m_Dataset.AddNew 'No call!
m_Dataset("OutOfThinAir") = "Hallo"
Set Me.Recordset = m_Dataset

With the help of Erik AII figured out a solution which works:在 Erik AII 的帮助下,找到了一个有效的解决方案:

Private Sub Form_Load()

  Dim rstADO As ADODB.Recordset
  Set rstADO = New ADODB.Recordset
  rstADO.Fields.Append "OutOfThinAir", adVarChar, 100, adFldMayBeNull
  rstADO.LockType = adLockOptimistic
  rstADO.Open

  rstADO.Addnew
  rstADO.Fields("OutOfThinAir") = "Hello"
  rstADO.Update
  rstADO.Addnew
  rstADO.Fields("OutOfThinAir") = "Du"
  rstADO.Update

  Set Me.Recordset = rstADO
End Sub

Btw I had to add "Microsoft ActiveX Data Objects 6.1 Library" as a reference in order to use the constants and "ADODB.Recordset" as a variabletype.顺便说一句,为了使用常量和“ADODB.Recordset”作为变量类型,我不得不添加“Microsoft ActiveX Data Objects 6.1 Library”作为参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM