|
本人不太会写代码,这是本人在该论坛下载的一个例子,本人改了一点,请教版主及各大侠帮帮眼,一般情况下,通过窗体添加记录的方法,如下代码可行吗?如有问题,恳请版主及各大侠指正,谢谢!
该代码是使用ADO的ADDNEW方法在窗体添加记录,如下:
Private Sub Command0_Click()
Dim db As ADODB.Connection, rs As ADODB.Recordset
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
rs.ActiveConnection = CurrentProject.Connection
rs.Open "商品信息", , adOpenKeyset, adLockPessimistic, adcmtable
If Trim(Text1.Value) <> "" Then
rs.AddNew
'rs.MoveLast
rs.Fields("名称") = Trim(Text1.Value)
rs.Fields("地址") = Trim(Text2.Value)
If MsgBox("是否添加该条记录?", vbYesNo, "系统提示") = vbYes Then
rs.Update
Me.Text1 = ""
Me.Text2 = ""
rs.Close
Else
Me.Text1 = ""
Me.Text2 = ""
End If
End If
End
End Sub |
|