AddNew Method Example

'This example uses the AddNew method to create a new record with the specified 'name. The AddName function is required for this procedure to run.  Sub AddNewX()  Dim dbsNorthwind As Database
Dim rstEmployees As Recordset
Dim strFirstName As String
Dim strLastName As String  Set dbsNorthwind = OpenDatabase("Northwind.mdb")
Set rstEmployees = _
  dbsNorthwind.OpenRecordset("Employees", dbOpenDynaset)  ' Get data from the user.
strFirstName = Trim(InputBox( _
  "Enter first name:"))
strLastName = Trim(InputBox( _
  "Enter last name:"))  ' Proceed only if the user actually entered something  ' for both the first and last names.
If strFirstName <> "" and strLastName <> "" Then    ' Call the function that adds the record.
  AddName rstEmployees, strFirstName, strLastName    ' Show the newly added data.
  With rstEmployees
  Debug.Print "New record: " &;amp; !FirstName &;amp; _
    " " &;amp; !LastName
  ' Delete new record because this is a demonstration.
  .Delete
  End With  Else
  Debug.Print _
  "You must input a string for first and last name!"  End If  rstEmployees.Close
dbsNorthwind.Close  End Sub  Function AddName(rstTemp As Recordset, _
strFirst As String, strLast As String)  ' Adds a new record to a Recordset using the data passed
' by the calling procedure. The new record is then made
' the current record.
With rstTemp
  .AddNew
  !FirstName = strFirst
  !LastName = strLast
  .Update
  .Bookmark = .LastModified
End With  End Function

 感谢原创者的辛勤劳动,希望对您有所帮助,转载请注明原出处。
 您可能对 [Asp.Net] 的这些文章也感兴趣:

ASP.NET动态数据预览版发布了
Asp.net中的页面乱码的问题
.Net FrameWork SDK文档的例子演示
跟ASP.NET MVC一起使用jQuery
ASP.NET中为DataGrid添加合计字段
缓存类的实现(C#)
ASP.NET设计网络硬盘之两重要类
用ASP.NET编写多层架构的系统
ATLServer与ASP.NET
在asp.net中做视频转换,将各种视频文件转换成.flv格式