|
楼主 |
发表于 2016-10-6 23:13
|
显示全部楼层
Private Sub CommandButton1_Click() '新增
On Error Resume Next
sql = "select * from 项目 where 项目名称='" & Me.TextBox3.Value & "'"
Set Rs = New ADODB.Recordset
With Rs
.ActiveConnection = Cnn
.Open sql, , adOpenKeyset, adLockPessimistic
End With
Me.TextBox2.Value = PY(Me.TextBox3.Value) & Application.WorksheetFunction.Text(Rs.RecordCount + 1, "000")
If MsgBox("是否添加新记录?", vbQuestion + vbYesNo, "提示") = vbNo Then Exit Sub
Rs.AddNew
For i = 1 To Rs.Fields.Count - 1
Rs.Fields(i) = Me.Controls("textbox" & i + 1).Value
Next i
Rs.Update
MsgBox "添加成功!", 64, "提示!"
Rs.Close
AddListView1
End Sub |
|