1,217
社区成员




Private Sub Form_Load()
Combo1.AddItem "板号"
Combo1.AddItem "元器件型号"
Combo1.AddItem "物料编码"
For i = 0 To 7
Text3(i) = ""
Text2 = ""
Next
End Sub
Private Sub Command1_Click()
If Text1.Text = "" Then
MsgBox "请输入查询内容:", vbInformation, "提示"
End If
Adodc1.RecordSource = "select 物料编码,工序,元器件型号,用量,封装,备注,类型,版号 from bom表 where 版号 like '%" & Text1.Text & "%'"
Adodc1.Refresh
If Combo1.Text = "元器件型号" Then
Adodc1.RecordSource = "select * from bom表 where 元器件型号 like '%" & Text1.Text & "%'"
Adodc1.Refresh
ElseIf Combo1.Text = "物料编码" Then
Adodc1.RecordSource = "select * from bom表 where 物料编码 like '%" & Text1.Text & "%'"
Adodc1.Refresh
Else
Adodc1.RecordSource = "select * from bom表 where 版号 like '%" & Text1.Text & "%'"
Adodc1.Refresh
End If
Text1.SetFocus
Text1.Text = ""
If Adodc1.Recordset.BOF And Adodc1.Recordset.EOF Then
MsgBox "没有你要找的BOM!", vbInformation + vbOKOnly, "提示"
End If
End Sub
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
Text2.Text = DataGrid1.Text
Dim i As Integer
For i = 0 To 7
Text3(i).Text = DataGrid1.Columns(i)
Next
End Sub
Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
Call Command3_Click
End If
End Sub
Private Sub Command3_Click()
If Text2.Text = "" Then
MsgBox "内容不能为空", 48, "提示"
Else
If a = MsgBox("数据已更改,是否存盘?", vbYesNo) Then
a = vbYes
DataGrid1.Text = Text2.Text
Adodc1.Recordset.Update
Adodc1.Refresh
Else
Exit Sub
End If
End If
End Sub
Private Sub Command2_Click()
If Text3(0).Text = "" Or Text3(1) = "" Or Text3(2) = "" Or Text3(3) = "" Or Text3(4) = "" Or Text3(6) = "" Or Text3(7) = "" Then
MsgBox "关键信息不能为空", 48, "提示"
Else
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("物料编码") = Trim(Text3(0).Text)
Adodc1.Recordset.Fields("工序") = Trim(Text3(1).Text)
Adodc1.Recordset.Fields("元器件型号") = Trim(Text3(2).Text)
Adodc1.Recordset.Fields("用量") = Val(Text3(3).Text)
Adodc1.Recordset.Fields("封装") = Trim(Text3(4).Text)
Adodc1.Recordset.Fields("备注") = Trim(Text3(5).Text)
Adodc1.Recordset.Fields("类型") = Trim(Text3(6).Text)
Adodc1.Recordset.Fields("版号") = Trim(Text3(7).Text)
Adodc1.Recordset.Update
Adodc1.Refresh
MsgBox "添加成功", 48, "提示"
End If
End Sub
Private Sub Text4_KeyPress(KeyAscii As Integer)
If KeyAscii = 46 Or (KeyAscii >= 48 And KeyAscii <= 57) Or (InStr(1, Text1, ",") = 0 And KeyAscii = 8) Then
Else
KeyAscii = 27
End If
End Sub
Private Sub Text3_KeyPress(Index As Integer, KeyAscii As Integer)
KeyAscii = xy(Index, KeyAscii)
End Sub
Function xy(Index As Integer, KeyAscii As Integer) As Integer
xy = 0
If KeyAscii = 8 Or KeyAscii = 46 Then
xy = KeyAscii '如果输入是del或退格,允许
Else
If Index = 3 And KeyAscii > 47 And KeyAscii < 58 Then
xy = KeyAscii 'i=0的文本框只能输入数字0-9
ElseIf Index = 1 Or Index = 2 Or Index = 4 Or Index = 5 Or Index = 6 Or Index = 7 Or Index = 0 Then
xy = KeyAscii 'i=0,1,2,4,5,6,7的文本框随便输入
End If
End If
End Function
Private Sub Form_Load()
Combo1.AddItem "板号"
Combo1.AddItem "元器件型号"
Combo1.AddItem "物料编码"
Text2 = ""
For i = 0 To 7
Text3(i) = ""
Next
Set DataGrid1.DataSource = Adodc1
End Sub