简体   繁体   中英

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. To do this I created a form with the defaultView = 1 (= continuous form).

Now I wonder if I can use show results from the webservice directly in my form. This means without creating a table which I then select with the recordsource-property.

Is there a way to show data a continuous-form in MS-Access without using a table?

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".

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. "SELECT 1 from dual;" does definitely not work.

Yes, but you'd need to use an ADODB recordset, not a DAO one.

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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