📄 frmupdateacc.frm
字号:
VERSION 5.00
Begin VB.Form frmUpdateAcc
Caption = "修改删除配件信息"
ClientHeight = 4665
ClientLeft = 60
ClientTop = 345
ClientWidth = 5295
LinkTopic = "Form1"
ScaleHeight = 4665
ScaleWidth = 5295
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton cmdCancel
Caption = "返回(&C)"
Height = 375
Left = 3480
TabIndex = 18
Top = 4080
Width = 1095
End
Begin VB.CommandButton cmdDelete
Caption = "删除(&D)"
Height = 375
Left = 2160
TabIndex = 17
Top = 4080
Width = 1095
End
Begin VB.CommandButton cmdUpdate
Caption = "修改(&U)"
Height = 375
Left = 720
TabIndex = 16
Top = 4080
Width = 1215
End
Begin VB.Frame Frame1
Caption = "配件信息"
Height = 2655
Index = 1
Left = 120
TabIndex = 3
Top = 1200
Width = 5055
Begin VB.TextBox txtAcc
Height = 285
Index = 0
Left = 840
TabIndex = 9
Text = "Text1"
Top = 360
Width = 1335
End
Begin VB.TextBox txtAcc
Enabled = 0 'False
Height = 285
Index = 1
Left = 3000
TabIndex = 8
Text = "Text2"
Top = 360
Width = 1695
End
Begin VB.TextBox txtAcc
Height = 285
Index = 2
Left = 840
TabIndex = 7
Text = "Text3"
Top = 840
Width = 1335
End
Begin VB.TextBox txtAcc
Height = 285
Index = 3
Left = 3000
TabIndex = 6
Text = "Text4"
Top = 840
Width = 1695
End
Begin VB.TextBox txtAcc
Height = 285
Index = 4
Left = 840
TabIndex = 5
Text = "Text5"
Top = 1320
Width = 3855
End
Begin VB.TextBox txtAcc
Height = 615
Index = 5
Left = 840
TabIndex = 4
Text = "Text6"
Top = 1800
Width = 3855
End
Begin VB.Label Label1
Caption = "名称:"
Height = 375
Index = 1
Left = 360
TabIndex = 15
Top = 360
Width = 1215
End
Begin VB.Label Label2
Caption = "编号:"
Height = 255
Left = 2520
TabIndex = 14
Top = 360
Width = 1215
End
Begin VB.Label Label3
Caption = "价格:"
Height = 255
Left = 360
TabIndex = 13
Top = 840
Width = 615
End
Begin VB.Label Label4
Caption = "数量:"
Height = 255
Left = 2520
TabIndex = 12
Top = 840
Width = 615
End
Begin VB.Label Label5
Caption = "备注:"
Height = 255
Left = 360
TabIndex = 11
Top = 1800
Width = 975
End
Begin VB.Label Label6
Caption = "厂家:"
Height = 255
Left = 360
TabIndex = 10
Top = 1320
Width = 975
End
End
Begin VB.Frame Frame1
Caption = "查询"
Height = 975
Index = 0
Left = 120
TabIndex = 0
Top = 120
Width = 5055
Begin VB.ComboBox cboNo
Height = 315
Left = 1560
TabIndex = 2
Text = "Combo1"
Top = 360
Width = 2055
End
Begin VB.Label Label1
Caption = "选择配件编号:"
Height = 255
Index = 0
Left = 240
TabIndex = 1
Top = 360
Width = 1335
End
End
End
Attribute VB_Name = "frmUpdateAcc"
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 cboNo_Click()
getAccInfo cboNo.Text
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdDelete_Click()
Dim conn As ADODB.Connection
'组合得到完成数据修改的SQL语句
sqlStr = "delete from accessories" _
& " where accNo='" & Trim(cboNo.Text) & "'"
On Error GoTo exitSub
Set conn = New ADODB.Connection
conn.Open connStr
'执行SQL语句
conn.Execute sqlStr
MsgBox "配件信息已删除!!"
initForm
exitSub:
conn.Close
End Sub
Private Sub cmdUpdate_Click()
Dim conn As ADODB.Connection
'组合得到完成数据修改的SQL语句
sqlStr = "update accessories set accName='" _
& txtAcc(0).Text & "',accPrice=" & txtAcc(2).Text _
& ",accStock=" & txtAcc(3).Text _
& ",producer='" & txtAcc(4).Text _
& "',[memo]='" & txtAcc(5).Text _
& "' where accNo='" & Trim(cboNo.Text) & "'"
On Error GoTo exitSub
Set conn = New ADODB.Connection
conn.Open connStr
'执行SQL语句
conn.Execute sqlStr
MsgBox "配件信息修改完成!!"
initForm
exitSub:
conn.Close
End Sub
Private Sub Form_Load()
'窗体居中显示
Me.Top = (Screen.Height - Me.Height) \ 2
Me.Left = (Screen.Width - Me.Width) \ 2
initForm
End Sub
Sub initAccNo()
Dim rstAccNo As ADODB.Recordset
'从配件表中读取所有配件编号并添加到组合列表框中
sqlStr = "select accNo from accessories"
Set rstAccNo = ExecuteSQL(sqlStr, msgText)
cboNo.Clear
If Not rstAccNo.EOF Then
Do While Not rstAccNo.EOF
cboNo.AddItem Trim(rstAccNo.Fields(0))
rstAccNo.MoveNext
Loop
cboNo.ListIndex = 0
Else
MsgBox "没有找到相关信息,请添加!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstAccNo.Close
End Sub
Sub getAccInfo(accNo As String)
'获取配件信息
Dim rstAcc As ADODB.Recordset
'从数据库中查找并显示配件信息
sqlStr = "select * from accessories" _
& " where accNo='" & accNo & "'"
Set rstAcc = ExecuteSQL(sqlStr, msgText)
If Not rstAcc.EOF Then
txtAcc(0).Text = rstAcc.Fields("accName")
txtAcc(1).Text = rstAcc.Fields("accNo")
txtAcc(2).Text = rstAcc.Fields("accPrice")
txtAcc(3).Text = rstAcc.Fields("accStock")
txtAcc(4).Text = rstAcc.Fields("producer")
txtAcc(5).Text = rstAcc.Fields("memo")
Else
MsgBox "没有找到相关信息,请添加!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstAcc.Close
End Sub
Sub initForm()
Dim i As Integer
For i = 0 To 5
txtAcc(i).Text = ""
Next i
initAccNo
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -