小弟能力有限,程序很冗长。。。。我再简化一下,多发点吧。。。。:
Private Sub FindFormInit()
DataGrid1.AllowUpdate = False
DataGrid2.AllowUpdate = False
cmdFind(2).Enabled = False
cmdFind(3).Enabled = False
cmdFind(9).Enabled = False
cmdFind(10).Enabled = False
Option1(0).Value = True
Option1(12).Value = True
FindIndex = 0
(下面设置了24个下拉菜单。。不用一一列出来了吧。。)
Adodc1.ConnectionString = connstring
strsql = "select a,b,c from s where a in ('140W','140')"
Adodc1.RecordSource = strsql
Adodc1.Refresh
If Adodc1.Recordset.RecordCount <> 0 Then
Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF
Combo1(0).AddItem Adodc1.Recordset.Fields(0)
Combo1(12).AddItem Adodc1.Recordset.Fields(0)
Adodc1.Recordset.MoveNext
Loop
Else
' MsgBox "", vbCritical
End If
strsql = "select a,b,c from s where a in ('141W','141')"
Adodc1.RecordSource = strsql
Adodc1.Refresh
If Adodc1.Recordset.RecordCount <> 0 Then
Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF
Combo1(1).AddItem Adodc1.Recordset.Fields(0)
Combo1(13).AddItem Adodc1.Recordset.Fields(0)
Adodc1.Recordset.MoveNext
Loop
Else
' MsgBox "", vbCritical
End If
。。。。。。。。。。。。。。略
strsql = "select a,b,c from s where a = '6D1'"
Adodc1.RecordSource = strsql
Adodc1.Refresh
If Adodc1.Recordset.RecordCount <> 0 Then
Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF
Combo1(11).AddItem Adodc1.Recordset.Fields(0)
Combo1(23).AddItem Adodc1.Recordset.Fields(0)
Adodc1.Recordset.MoveNext
Loop
Else
' MsgBox "", vbCritical
Exit Sub
End If
End Sub
Private Sub Option1_Click(Index As Integer)
Select Case Index
Case 0
Combo1(0).Enabled = True
Combo1(1).Enabled = False
Combo1(2).Enabled = False
Combo1(3).Enabled = False
Combo1(4).Enabled = False
Combo1(5).Enabled = False
Combo1(6).Enabled = False
Combo1(7).Enabled = False
Combo1(8).Enabled = False
Combo1(9).Enabled = False
Combo1(10).Enabled = False
Combo1(11).Enabled = False
Combo1(1).Text = ""
Combo1(2).Text = ""
Combo1(3).Text = ""
Combo1(4).Text = ""
Combo1(5).Text = ""
Combo1(6).Text = ""
Combo1(7).Text = ""
Combo1(8).Text = ""
Combo1(9).Text = ""
Combo1(10).Text = ""
Combo1(11).Text = ""
Case 1
Combo1(0).Enabled = False
Combo1(1).Enabled = True
Combo1(2).Enabled = False
Combo1(3).Enabled = False
Combo1(4).Enabled = False
Combo1(5).Enabled = False
Combo1(6).Enabled = False
Combo1(7).Enabled = False
Combo1(8).Enabled = False
Combo1(9).Enabled = False
Combo1(10).Enabled = False
Combo1(11).Enabled = False
Combo1(0).Text = ""
Combo1(2).Text = ""
Combo1(3).Text = ""
Combo1(4).Text = ""
Combo1(5).Text = ""
Combo1(6).Text = ""
Combo1(7).Text = ""
Combo1(8).Text = ""
Combo1(9).Text = ""
Combo1(10).Text = ""
Combo1(11).Text = ""
(Case 2~Case 10的内容。。估计看了其他的就能够知道了吧。。我用的是最笨的方法,全部列出来)
Case 11
Combo1(0).Enabled = False
Combo1(1).Enabled = False
Combo1(2).Enabled = False
Combo1(3).Enabled = False
Combo1(4).Enabled = False
Combo1(5).Enabled = False
Combo1(6).Enabled = False
Combo1(7).Enabled = False
Combo1(8).Enabled = False
Combo1(9).Enabled = False
Combo1(10).Enabled = False
Combo1(11).Enabled = True
Combo1(1).Text = ""
Combo1(2).Text = ""
Combo1(3).Text = ""
Combo1(4).Text = ""
Combo1(5).Text = ""
Combo1(6).Text = ""
Combo1(7).Text = ""
Combo1(8).Text = ""
Combo1(9).Text = ""
Combo1(10).Text = ""
Combo1(0).Text = ""
Case 12
Combo1(12).Enabled = True
Combo1(13).Enabled = False
Combo1(14).Enabled = False
Combo1(15).Enabled = False
Combo1(16).Enabled = False
Combo1(17).Enabled = False
Combo1(18).Enabled = False
Combo1(19).Enabled = False
Combo1(20).Enabled = False
Combo1(21).Enabled = False
Combo1(22).Enabled = False
Combo1(23).Enabled = False
Combo1(13).Text = ""
Combo1(14).Text = ""
Combo1(15).Text = ""
Combo1(16).Text = ""
Combo1(17).Text = ""
Combo1(18).Text = ""
Combo1(19).Text = ""
Combo1(20).Text = ""
Combo1(21).Text = ""
Combo1(22).Text = ""
Combo1(23).Text = ""
(Case 13~Case 22的内容。。也同上方法)
Case 23
Combo1(12).Enabled = False
Combo1(13).Enabled = False
Combo1(14).Enabled = False
Combo1(15).Enabled = False
Combo1(16).Enabled = False
Combo1(17).Enabled = False
Combo1(18).Enabled = False
Combo1(19).Enabled = False
Combo1(20).Enabled = False
Combo1(21).Enabled = False
Combo1(22).Enabled = False
Combo1(23).Enabled = True
Combo1(12).Text = ""
Combo1(13).Text = ""
Combo1(14).Text = ""
Combo1(15).Text = ""
Combo1(16).Text = ""
Combo1(17).Text = ""
Combo1(18).Text = ""
Combo1(19).Text = ""
Combo1(20).Text = ""
Combo1(21).Text = ""
Combo1(22).Text = ""
End Select
FindIndex = Index
End Sub
Private Sub cmdFind_Click(Index As Integer)
Adodc1.ConnectionString = connstring
Adodc2.ConnectionString = connstring
Adodc3.ConnectionString = connstring
Adodc4.ConnectionString = connstring
Adodc5.ConnectionString = connstring
Adodc6.ConnectionString = connstring
Select Case Index
Case 0 Select Case FindIndex
Case 0
strsql = "SELECT a,b,c, FROM s Where b = '" + Trim(Combo1(0).Text) + "' AND a in('140W','140')"
strsql2 = "SELECT d,e,f FROM x Where b = '" + Trim(Combo1(0).Text) + "' AND a in('140W','140')"
Case 1
strsql = "SELECT a,b,c, FROM s Where b = '" + Trim(Combo1(1).Text) + "' AND a in('141W','141')"
strsql2 = "SELECT a,b,c, FROM x Where b = '" + Trim(Combo1(1).Text) + "' AND a in('141W','141')"
Case 2
.....
Case 3
.....
Case 4
......
Case 5
......
Case 6
......
Case 7
......
Case 8
......
Case 9
......
Case 10
......
Case 11
strsql = "SELECT a,b,c, FROM s Where b = '" + Trim(Combo1(11).Text) + "' AND a ='6D1'"
strsql2 = "SELECT a,b,c, FROM x Where b = '" + Trim(Combo1(11).Text) + "' AND a ='6D1'"
End Select
Adodc1.RecordSource = strsql
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
For i = 0 To 10
Text1(i).Text = Adodc1.Recordset.Fields(i)
Next i
Adodc2.RecordSource = strsql2
Adodc2.Refresh
Set DataGrid1.DataSource = Adodc2
Else
MsgBox " ", vbCritical
Exit Sub
End If
Case 1
Option1(0).Value = False
For i = 0 To 11
Combo1(i).Enabled = False
Combo1(i).Text = ""
Next i
cmdFind(2).Enabled = True
cmdFind(3).Enabled = True
For i = 0 To 10
Text1(i).Text = ""
Next i
DataGrid1.AllowUpdate = True
DataGrid1.AllowAddNew = True
cmdFind(1).Visible = False
cmdFind(5).Visible = True
cmdFind(0).Enabled = False
Frame8.Visible = True
For i = 26 To 32
Label1(i).Visible = True
Next i
For i = 22 To 28
Text1(i).Visible = True
Next i
For i = 29 To 35
Text1(i).Visible = True
Next i
For i = 36 To 42
Text1(i).Visible = True
Next i
For i = 43 To 49
Text1(i).Visible = True
Next i
For i = 50 To 56
Text1(i).Visible = True
Next i
DataGrid1.Visible = False
Case 2
strsql = "SELECT a,b,c FROM s Where a = '" + Trim(Text1(3).Text) + "' AND b='" + Trim(Text1(2).Text) + "'"
strsql2 = "SELECT d,e,f FROM x Where a = '" + Trim(Text1(3).Text) + "' AND b='" + Trim(Text1(2).Text) +"'"
strsql3 = "SELECT 略了吧"
strsql4 = "SELECT 略"
Adodc1.RecordSource = strsql
Adodc1.Refresh
Adodc1.Recordset.AddNew
For i = 0 To 10
Adodc1.Recordset.Fields(i) = Text1(i).Text
Next i
Adodc1.Recordset.Update
Adodc2.RecordSource = strsql2
Adodc2.Refresh
Adodc2.Recordset.AddNew
Adodc2.Recordset.Fields(0) = Text1(2).Text
Adodc2.Recordset.Fields(1) = Text1(3).Text
For i = 22 To 28
Adodc2.Recordset.Fields(i - 20) = Text1(i).Text
Next i
Adodc2.Recordset.Update
Adodc3.RecordSource = strsql3
Adodc3.Refresh
Adodc3.Recordset.AddNew
Adodc3.Recordset.Fields(0) = Trim(Text1(2).Text)
Adodc3.Recordset.Fields(1) = Trim(Text1(3).Text)
For i = 29 To 35
Adodc3.Recordset.Fields(i - 27) = Trim(Text1(i).Text)
Next i
Adodc3.Recordset.Update
Adodc4.RecordSource = strsql4
Adodc4.Refresh
Adodc4.Recordset.AddNew
Adodc4.Recordset.Fields(0) = Trim(Text1(2).Text)
Adodc4.Recordset.Fields(1) = Trim(Text1(3).Text)
For i = 36 To 42
Adodc4.Recordset.Fields(i - 34) = Trim(Text1(i).Text)
Next i
Adodc4.Recordset.Update
Adodc5.RecordSource = strsql3
Adodc5.Refresh
Adodc5.Recordset.AddNew
Adodc5.Recordset.Fields(0) = Trim(Text1(2).Text)
Adodc5.Recordset.Fields(1) = Trim(Text1(3).Text)
For i = 43 To 49
Adodc5.Recordset.Fields(i - 41) = Trim(Text1(i).Text)
Next i
Adodc5.Recordset.Update
Adodc6.RecordSource = strsql4
Adodc6.Refresh
Adodc6.Recordset.AddNew
Adodc6.Recordset.Fields(0) = Trim(Text1(2).Text)
Adodc6.Recordset.Fields(1) = Trim(Text1(3).Text)
For i = 50 To 56
Adodc6.Recordset.Fields(i - 48) = Trim(Text1(i).Text)
Next i
Adodc6.Recordset.Update
MsgBox "", vbInformation + vbOKOnly, ""
For i = 0 To 10
Text1(i).Text = ""
Next i
For i = 22 To 56
Text1(i).Text = ""
Next i
strsql = "select 。。。"
Adodc1.RecordSource = strsql
Adodc1.Refresh
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields(0) = gUserName
Adodc1.Recordset.Fields(1) = ""
Adodc1.Recordset.Fields(2) = Date
Adodc1.Recordset.Fields(3) = time
Adodc1.Recordset.Update
(记录操作的dd。。)
'刷新下拉菜单
For i = 0 To 24
Combo1(i).Clear
Next
(和上面设置下拉菜单的代码一样。。略)
Case 3
For i = 0 To 10
Text1(i).Text = ""
Next i
For i = 22 To 56
Text1(i).Text = ""
Next i
Case 4
Unload Me
End
Case 5
DataGrid1.AllowUpdate = False
DataGrid1.AllowAddNew = False
cmdFind(1).Visible = True
cmdFind(5).Visible = False
cmdFind(0).Enabled = True
cmdFind(2).Enabled = False
cmdFind(3).Enabled = False
Option1(0).Value = True
Frame8.Visible = False
For i = 26 To 32
Label1(i).Visible = False
Next i
For i = 22 To 28
Text1(i).Visible = False
Next i
For i = 29 To 35
Text1(i).Visible = False
Next i
For i = 36 To 42
Text1(i).Visible = False
Next i
For i = 43 To 49
Text1(i).Visible = False
Next i
For i = 50 To 56
Text1(i).Visible = False
Next i
DataGrid1.Visible = True
Case 6
Select Case FindIndex
Case 12
strsql = "SELECT ...略"
strsql2= "SELECT ...略"
除了Trim(Combo1(0).text)变为Trim(Combo1(12).text)外,其余同Case 0
Case 13
( 变化同上,下面的都略了吧,反正都是下拉菜单变了,而下拉内容不变的情况)
Case 14
Case 15
Case 16
Case 17
Case 18
Case 19
Case 20
Case 21
Case 22
Case 23
End Select
Adodc1.RecordSource = strsql
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
For i = 11 To 21
Text1(i).Text = Adodc1.Recordset.Fields(i - 11)
Next i
Adodc2.RecordSource = strsql2
Adodc2.Refresh
Set DataGrid2.DataSource = Adodc2
Else
MsgBox "", vbCritical
Exit Sub
End If
Case 7
cmdFind(9).Enabled = True
cmdFind(10).Enabled = True
DataGrid2.AllowUpdate = True
DataGrid2.AllowAddNew = True
DataGrid2.AllowDelete = True
cmdFind(7).Visible = False
cmdFind(8).Visible = True
Case 8
cmdFind(9).Enabled = False
cmdFind(10).Enabled = False
DataGrid2.AllowUpdate = False
DataGrid2.AllowAddNew = False
DataGrid2.AllowDelete = False
cmdFind(7).Visible = True
cmdFind(8).Visible = False
Case 9
With Adodc1.Recordset
.Delete
If .EOF Then
.MoveLast
Else
.MoveNext
End If
End With
strsql = "SELECT "
strsql2 = "SELECT "
Adodc1.RecordSource = strsql
Adodc1.Refresh
Adodc1.Recordset.AddNew
For i = 11 To 21
Adodc1.Recordset.Fields(i - 11) = Text1(i).Text
Text1(i).Text = ""
Next i
Adodc1.Recordset.Update
Adodc2.RecordSource = strsql2
Adodc2.Refresh
Adodc2.Recordset.Update
MsgBox "", vbInformation + vbOKOnly, ""
strsql2 = "SELECT "
Adodc2.RecordSource = strsql2
Adodc2.Refresh
Set DataGrid2.DataSource = Adodc2
strsql = "select "
Adodc1.RecordSource = strsql
Adodc1.Refresh
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields(0) = gUserName
Adodc1.Recordset.Fields(1) = ""
Adodc1.Recordset.Fields(2) = Date
Adodc1.Recordset.Fields(3) = time
Adodc1.Recordset.Update
Case 10
If MsgBox("", vbExclamation + vbOKCancel, "") = vbCancel Then
Exit Sub
End If
With Adodc1.Recordset
If .RecordCount <= 0 Then
MsgBox "", vbInformation + vbOKOnly, ""
Exit Sub
End If
.Delete
If .EOF Then
.MoveLast
Else
.MoveNext
End If
For i = 11 To 21
Text1(i).Text = ""
Next i
End With
With Adodc2.Recordset
If .RecordCount > 0 Then
.Delete
Else
End If
If .EOF Then
.MoveLast
Else
.MoveNext
End If
End With
strsql2 = "SELECT "
Adodc2.RecordSource = strsql2
Adodc2.Refresh
Set DataGrid2.DataSource = Adodc2
strsql = "select "
Adodc1.RecordSource = strsql
Adodc1.Refresh
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields(0) = gUserName
Adodc1.Recordset.Fields(1) = ""
Adodc1.Recordset.Fields(2) = Date
Adodc1.Recordset.Fields(3) = time
Adodc1.Recordset.Update
Case 11
Unload Me
End
End Select
End Sub