本例子采用ADO,将指定的值写入自动编号,但在下次添加记录时自动编号会在用ADO写入值的基础上加1。
Private Sub Command10_Click()
Dim con As New ADODB.Connection
Dim rec As New ADODB.Recordset
Dim strSQL As String
Set con = CurrentProject.Connection
strSQL = "SELECT * FROM 日记 "
rec.Open strSQL, con, adOpenKeyset, adLockPessimistic
With rec
.AddNew
If Not IsNull(Me.Text1) Then
.Fields("ID") = Me.Text1 '在Text1文本框中写入值后,该值将被写入指定自动编号ID当中。
End If
.Fields("日期") = Me.Text7
.Fields("内容") = Me.Text3
.Update
End With
rec.Close
Set con = Nothing
Set rec = Nothing
Me.Text1 = Null
Me.Text7 = Date
Me.Text3 = Null
Me.Child2.Requery
MsgBox "添加成功!"
End Sub
[此贴子已经被作者于2006-2-14 21:20:17编辑过]
|