📄 frmupdateclient.frm
字号:
VERSION 5.00
Begin VB.Form frmUpdateClient
Caption = "删改客户信息"
ClientHeight = 4200
ClientLeft = 60
ClientTop = 345
ClientWidth = 5895
LinkTopic = "Form1"
ScaleHeight = 4200
ScaleWidth = 5895
StartUpPosition = 3 'Windows Default
Begin VB.Frame Frame1
Caption = "客户信息"
Height = 2175
Index = 1
Left = 120
TabIndex = 7
Top = 1200
Width = 5655
Begin VB.TextBox txtClient
Enabled = 0 'False
Height = 285
Index = 0
Left = 1200
TabIndex = 12
Text = "Text1"
Top = 360
Width = 1575
End
Begin VB.TextBox txtClient
Height = 285
Index = 1
Left = 3840
TabIndex = 11
Text = "Text2"
Top = 360
Width = 1575
End
Begin VB.TextBox txtClient
Height = 285
Index = 2
Left = 1200
TabIndex = 10
Text = "Text3"
Top = 840
Width = 1575
End
Begin VB.TextBox txtClient
Height = 285
Index = 3
Left = 3720
TabIndex = 9
Text = "Text4"
Top = 840
Width = 1695
End
Begin VB.TextBox txtClient
Height = 615
Index = 4
Left = 1200
TabIndex = 8
Text = "Text5"
Top = 1320
Width = 4215
End
Begin VB.Label Label1
Caption = "客户名称:"
Height = 255
Index = 1
Left = 240
TabIndex = 17
Top = 360
Width = 1215
End
Begin VB.Label Label2
Caption = "联 系 人:"
Height = 255
Left = 2880
TabIndex = 16
Top = 360
Width = 975
End
Begin VB.Label Label3
Caption = "电话:"
Height = 255
Left = 600
TabIndex = 15
Top = 840
Width = 615
End
Begin VB.Label Label4
Caption = "E-mail:"
Height = 255
Left = 3120
TabIndex = 14
Top = 840
Width = 735
End
Begin VB.Label Label5
Caption = "备注:"
Height = 255
Left = 600
TabIndex = 13
Top = 1320
Width = 615
End
End
Begin VB.CommandButton cmdCancel
Caption = "返回(&C)"
Height = 375
Left = 3600
TabIndex = 6
Top = 3600
Width = 1215
End
Begin VB.CommandButton cmdDelete
Caption = "删除(&D)"
Height = 375
Left = 2160
TabIndex = 5
Top = 3600
Width = 1215
End
Begin VB.CommandButton cmdUpdate
Caption = "修改(&U)"
Height = 375
Left = 720
TabIndex = 4
Top = 3600
Width = 1215
End
Begin VB.Frame Frame1
Caption = "查询"
Height = 975
Index = 0
Left = 120
TabIndex = 0
Top = 120
Width = 5655
Begin VB.CommandButton cmdQuery
Caption = "查询(&Q)"
Height = 375
Left = 3480
TabIndex = 3
Top = 360
Width = 1215
End
Begin VB.TextBox txtClientName
Height = 285
Left = 1200
TabIndex = 2
Top = 360
Width = 1935
End
Begin VB.Label Label1
Caption = "客户名称:"
Height = 255
Index = 0
Left = 240
TabIndex = 1
Top = 360
Width = 975
End
End
End
Attribute VB_Name = "frmUpdateClient"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public sqlStr As String
Public msgText As String
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdDelete_Click()
Dim conn As ADODB.Connection
'组合得到完成数据删除的SQL语句
sqlStr = "delete from client where" _
& " [clientName]='" & Trim(txtClient(0).Text) & "'"
On Error GoTo exitSub
Set conn = New ADODB.Connection
conn.Open connStr
'执行SQL语句
conn.Execute sqlStr
MsgBox "成功删除数据!!"
clearTextBox
exitSub:
conn.Close
End Sub
Private Sub cmdQuery_Click()
getClientInfo txtClientName.Text
End Sub
Private Sub cmdUpdate_Click()
Dim conn As ADODB.Connection
'组合得到完成数据修改的SQL语句
sqlStr = "update client set [email]='" & txtClient(3).Text _
& "',[telno]='" & txtClient(2).Text _
& "',[contact]='" & txtClient(1).Text _
& "',[memo]='" & txtClient(4).Text _
& "' where [clientName]='" & Trim(txtClient(0).Text) & "'"
On Error GoTo exitSub
Set conn = New ADODB.Connection
conn.Open connStr
'执行SQL语句
conn.Execute sqlStr
MsgBox "成功修改数据!!"
clearTextBox
exitSub:
conn.Close
End Sub
Private Sub Form_Load()
clearTextBox
End Sub
Sub clearTextBox()
Dim i As Integer
For i = 0 To 4
txtClient(i).Text = ""
Next i
End Sub
Sub getClientInfo(name As String)
'获取并显示客户信息
Dim rstClient As ADODB.Recordset
'从客户信息表中查找客户信息并在窗体上显示出来供修改
sqlStr = "select * from client where" _
& " clientName='" & txtClientName.Text & "'"
Set rstClient = ExecuteSQL(sqlStr, msgText)
If Not rstClient.EOF Then
txtClient(0).Text = Trim(rstClient.Fields("clientName"))
txtClient(1).Text = Trim(rstClient.Fields("contact"))
txtClient(2).Text = Trim(rstClient.Fields("telno"))
txtClient(3).Text = Trim(rstClient.Fields("email"))
txtClient(4).Text = Trim(rstClient.Fields("memo"))
Else
MsgBox "没有找到相关信息,请添加!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstClient.Close
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -