用没有绑定的控件实现数据添加
但有个问题,如何实现修改的功能啊??代码。
谢谢了先
急啊。。Dim mydb1 As Database     '定义数据库
Dim myrs1 As Recordset     '定义字段
Dim i As Integer     '定义一个整型变量
Private Sub cmdcancel_Click()
 For i = 0 To 2
  Text1(1).Text = ""
  Text1(2).Text = ""
 Next i
End SubPrivate Sub Form_Load()
  '建立数据源的连接
 Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb;Persist Security Info=False"
 '查询所有记录,并按"部门编号"排序
 Adodc1.RecordSource = "select * from splbb order by splbbh"
 Adodc1.Refresh
For i = 0 To 2
  Text1(i).Enabled = False
 Next i
cmdsave.Enabled = FalseEnd SubPrivate Sub CmdAdd_Click()
 '建立数据源的连接
 Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb;Persist Security Info=False"
'生成产品编号
 Adodc1.RecordSource = "select * from splbb order by splbbh"
 Adodc1.Refresh If Adodc1.Recordset.RecordCount > 0 Then
  If Not Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast
  If Adodc1.Recordset.Fields("splbbh") <> "" Then Text1(0).Text = "p" & Format(Val(Right(Adodc1.Recordset.Fields("splbbh"), 3)) + 1, "000")
 Else
  Text1(0).Text = "p001"
 End If'添加记录
 For i = 0 To 2
 
   Text1(i).Enabled = True
   Text1(1).Text = ""
   Text1(2).Text = ""
 Next i
 Text1(1).SetFocus
 
  cmdadd.Enabled = False
 cmddelete.Enabled = False
 cmdsave.Enabled = True
 
End SubPrivate Sub CmdDelete_Click()     '删除记录
 Dim myval As String
 myval = MsgBox("是否要删除该记录?", vbYesNo)
 If myval = vbYes Then
  Adodc1.Recordset.Delete
  Adodc1.Recordset.MoveNext
  If Adodc1.Recordset.EOF = True Then Adodc1.Recordset.MoveLast
    For i = 0 To 2
        Text1(i).Enabled = False
    Next i
 End If
End Sub
Private Sub CmdSave_Click()
If Text1(0).Text = "" Then
   MsgBox "编号不允许为空!"
   Exit Sub
 End If
 If Text1(1).Text = "" Then
   MsgBox "名称不允许为空!"
   Exit Sub
 End If
 
 Adodc1.Recordset.AddNew
 For i = 0 To 2
     If Text1(i) <> "" Then Adodc1.Recordset.Fields(i) = Text1(i).Text
 Next iAdodc1.Recordset.Update      '更新记录
 MsgBox "数据已成功保存!" '设置控件不可用
 For i = 0 To 2
     Text1(i).Enabled = False
 Next i
  cmdsave.Enabled = False
 cmdadd.Enabled = True
 cmddelete.Enabled = True
End Sub
Private Sub CmdExit_Click()
  Unload Me
End Sub

解决方案 »

  1.   

    新增:.AddNew
          ......
          .update修改 ......
        .update删除.delete
      

  2.   

    Private Sub btn_ok_Click()
     Dim conn As ADODB.Connection
     Dim rs As ADODB.Recordset
     Dim strCoded$, strPassword$, strSQL$
     Static count As Byte'数据格式化
     strcode = Trim(txt_username.Text)
     strPassword = Replace(Trim(txt_password.Text), "", "")'非空验证
     If strcode = "" And strPassword <> "" Then
        MsgBox "用户名不能为空,请输入用户名!", Buttons = vbOKCancel, "登录错误"
        txt_username.SetFocus
      
      ElseIf strPassword = "" And strcode <> "" Then
         MsgBox "口令不能为空,请输入用户名!", Button = vbOK, "登录错误"
        txt_password.SetFocus
      
      ElseIf strcode = "" And strPassword = "" Then
          MsgBox "用户名和口令不能为空,请重新输入!", Buttons = vbOKCancel, "登录错误"
          txt_username.SetFocus
     End If'查询数据库中是否有合法用户
    If strcode <> "" And strPassword <> "" Then
      Set conn = New ADODB.Connection
      Set rs = New ADODB.Recordset
      strSQL = "select * from c_opertion where opercode= '" & strcode & "'  and operpw= '" & strPassword & "' "
      conn.Open Module1.connstring
      rs.Open strSQL, conn   If rs.EOF Then    '登录不成功
          count = count + 1
          MsgBox "用户名不存在或密码不正确,请重新输入!", Button = vbOK, "登录错误"
          txt_username.Text = ""
          txt_password.Text = ""
          txt_username.SetFocus
       Else               '登录成功
          loginsucceeded = True
          
          usercode = strcode
          userright = rs("operright").Value
          
          Me.Hide
       End If
       
      '关闭数据集、连接并释放
      rs.Close
      conn.Close
      Set rs = Nothing
      Set conn = Nothing
    End If
     
     '退出系统
    If count >= 3 Then
         MsgBox "超过3次登录失败,无权登录系统!", vbYes, "登录失败"
         End
    End If
      
    End Sub