回覆列表
  • 1 # 錢布斯

    Private Sub Command1_Click()

    Dim ADOrs As New Recordset "宣告一個記錄集物件

    Dim ADOrs1 As New Recordset "宣告一個記錄集物件

    Dim strSQL As String

    Dim user As String

    ADOrs.ActiveConnection = ADOcn "與ADOcn連線物件關聯

    ADOrs1.ActiveConnection = ADOcn "與ADOcn連線物件關聯

    If Text1.Text = "" Then

    MsgBox "未輸入姓名資訊,請重新輸入!", vbCritical + vbOKOnly

    Text1.SetFocus "定位游標

    Exit Sub

    End If

    If Text2.Text = "" Then

    MsgBox "未輸入身份證號碼,請重新輸入!", vbCritical + vbOKOnly

    Text2.SetFocus "定位游標

    Exit Sub

    End If

    "首先查詢表中是否存在關鍵字相同的記錄

    strSQL = "select * from Persons"

    strSQL = strSQL & " Where 身份證號="" + Text2.Text + """

    ADOrs.Open strSQL

    "如果關鍵字重複,則退出

    If Not ADOrs.EOF Then

    MsgBox "該個人資訊記錄已經存在,不能繼續增加", vbCritical + vbOKOnly

    Exit Sub

    End If

    ADOrs1.Open "select * from Persons", , , adLockOptimistic

    ADOrs1.AddNew

    ADOrs1("姓名") = Text1.Text

    ADOrs1("身份證號") = Text2.Text

    ADOrs1("工號") = Text3.Text

    ADOrs1("所屬公司") = Text4.Text

    ADOrs1("部門") = Text5.Text

    ADOrs1("聯絡電話") = Text6.Text

    ADOrs1("聯絡地址") = Text7.Text

    ADOrs1.Update

    user = Text1.Text

    Text1.Text = "" "初始化文字框控制元件

    Text2.Text = ""

    Text3.Text = ""

    Text4.Text = ""

    Text5.Text = ""

    Text6.Text = ""

    Text7.Text = ""

    Text1.SetFocus "定位游標

    MDIForm1.StatusBar1.Panels(1).Text = "成功添加個人資訊:" & user

    MsgBox "已成功新增新記錄", vbQuestion + vbOKOnly

    ADOrs.Close "關閉記錄集

    ADOrs1.Close "關閉記錄集

    Set ADOrs = Nothing

    Set ADOrs1 = Nothing

    End Sub

  • 中秋節和大豐收的關聯?
  • 哪類鏡頭更容易出現“紫邊現象”或“紅綠邊現象”?