我的msn: myfend@
Option Explicit
Private conn As ADODB.Connection
Private Rst As New ADODB.Recordset
Dim arrMonth(12) As String
Private Sub Command1_Click()
Dim intListIndex As Integer
Dim strMonth As String
intListIndex = Combo1.ListIndex
strMonth = arrMonth(intListIndex)
'MsgBox strMonth
'declare rs As Recordset,con As Connection Objects
'rs.Open "SELECT xxx FROM " & strMonth ,con, ,
End Sub
Private Sub Form_Load()
Dim ConString As String
Dim i As Integer
For i = 0 To UBound(arrMonth) - 1
arrMonth(i) = "f" & (i + 1) & "表"
Combo1.AddItem arrMonth(i)
Next
ConString = "Provider=Microsoft.Jet.OleDb.4.0;Persist Security Info = False;" _
& "Data Source =" & App.Path & "\db1.mdb;Jet OleDb:"
Set conn = CreateObject("ADODB.Connection")
With conn
.ConnectionString = ConString
.Open
End With
End Sub
执行后,没有反应!!
Combo1的属性设置仍然就在List里面设定了12个月。其余未作改动!
改:
Option Explicit
Private conn As ADODB.Connection
Private Rst As New ADODB.Recordset
Dim arrMonth(12) As String
Private Sub Command1_Change()
Dim intListIndex As Integer
Dim strMonth As String
intListIndex = Combo1.ListIndex
strMonth = arrMonth(intListIndex)
Rst.Open "Select * From " & strMonth, conn
If Rst.RecordCount > 0 Then
n.Text = Rst.Fields("n").Value & ""
Text1(0).Text = Rst.Fields("zy1").Value & ""
Text1(1).Text = Rst.Fields("zy2").Value & ""
Text1(2).Text = Rst.Fields("zy3").Value & ""
Text1(3).Text = Rst.Fields("zy4").Value & ""
Text1(4).Text = Rst.Fields("zy5").Value & ""
Text1(5).Text = Rst.Fields("zy6").Value & ""
Text1(6).Text = Rst.Fields("zy7").Value & ""
Text1(7).Text = Rst.Fields("zy8").Value & ""
Text1(8).Text = Rst.Fields("zy9").Value & ""
Text2(0).Text = Rst.Fields("z(1)").Value & ""
Text2(1).Text = Rst.Fields("z(2)").Value & ""
Text2(2).Text = Rst.Fields("z(3)").Value & ""
Text2(3).Text = Rst.Fields("z(4)").Value & ""
Text2(4).Text = Rst.Fields("z(5)").Value & ""
Text2(5).Text = Rst.Fields("z(6)").Value & ""
Text2(6).Text = Rst.Fields("z(7)").Value & ""
Text2(7).Text = Rst.Fields("z(8)").Value & ""
Text2(8).Text = Rst.Fields("z(9)").Value & ""
Text3(0).Text = Rst.Fields("m1").Value & ""
Text3(1).Text = Rst.Fields("m2").Value & ""
Text3(2).Text = Rst.Fields("m3").Value & ""
Text3(3).Text = Rst.Fields("m4").Value & ""
Text3(4).Text = Rst.Fields("m5").Value & ""
Text3(5).Text = Rst.Fields("m6").Value & ""
Text3(6).Text = Rst.Fields("m7").Value & ""
Text3(7).Text = Rst.Fields("m8").Value & ""
Text3(8).Text = Rst.Fields("m9").Value & ""
Text4(0).Text = Rst.Fields("j(1)").Value & ""
Text4(1).Text = Rst.Fields("j(2)").Value & ""
Text4(2).Text = Rst.Fields("j(3)").Value & ""
Text4(3).Text = Rst.Fields("j(4)").Value & ""
Text4(4).Text = Rst.Fields("j(5)").Value & ""
Text4(5).Text = Rst.Fields("j(6)").Value & ""
Text4(6).Text = Rst.Fields("j(7)").Value & ""
Text4(7).Text = Rst.Fields("j(8)").Value & ""
Text4(8).Text = Rst.Fields("j(9)").Value & ""
Text4(9).Text = Rst.Fields("j10").Value & ""
Text5(0).Text = Rst.Fields("d(1)").Value & ""
Text5(1).Text = Rst.Fields("d(2)").Value & ""
Text5(2).Text = Rst.Fields("d(3)").Value & ""
Text5(3).Text = Rst.Fields("d(4)").Value & ""
Text5(4).Text = Rst.Fields("d(5)").Value & ""
Text5(5).Text = Rst.Fields("d(6)").Value & ""
Text5(6).Text = Rst.Fields("d(7)").Value & ""
Text5(7).Text = Rst.Fields("d(8)").Value & ""
Text5(8).Text = Rst.Fields("d(9)").Value & ""
Text5(9).Text = Rst.Fields("d10").Value & ""
Label14.Caption = Rst.AbsolutePosition
Label16.Caption = Rst.AbsolutePosition
Label11.Caption = Rst.RecordCount
Else
n.Text = ""
Text1(0).Text = ""
Text1(1).Text = ""
Text1(2).Text = ""
Text1(3).Text = ""
Text1(4).Text = ""
Text1(5).Text = ""
Text1(6).Text = ""
Text1(7).Text = ""
Text1(8).Text = ""
Text2(0).Text = ""
Text2(1).Text = ""
Text2(2).Text = ""
Text2(3).Text = ""
Text2(4).Text = ""
Text2(5).Text = ""
Text2(6).Text = ""
Text2(7).Text = ""
Text2(8).Text = ""
Text3(0).Text = ""
Text3(1).Text = ""
Text3(2).Text = ""
Text3(3).Text = ""
Text3(4).Text = ""
Text3(5).Text = ""
Text3(6).Text = ""
Text3(7).Text = ""
Text3(8).Text = ""
Text4(0).Text = ""
Text4(1).Text = ""
Text4(2).Text = ""
Text4(3).Text = ""
Text4(4).Text = ""
Text4(5).Text = ""
Text4(6).Text = ""
Text4(7).Text = ""
Text4(8).Text = ""
Text4(9).Text = ""
Text5(0).Text = ""
Text5(1).Text = ""
Text5(2).Text = ""
Text5(3).Text = ""
Text5(4).Text = ""
Text5(5).Text = ""
Text5(6).Text = ""
Text5(7).Text = ""
Text5(8).Text = ""
Text5(9).Text = ""
Label11.Caption = ""
Label14.Caption = ""
Label16.Caption = ""
End If
Text4(9).ForeColor = RGB(0, 0, 150)
Text5(9).ForeColor = RGB(0, 0, 150)
End Sub
Private Sub Form_Load()
Dim ConString As String
Dim i As Integer
For i = 0 To UBound(arrMonth) - 1
arrMonth(i) = "f" & (i + 1) & "表"
Combo1.AddItem arrMonth(i)
Next
ConString = "Provider=Microsoft.Jet.OleDb.4.0;Persist Security Info = False;" _
& "Data Source =" & App.Path & "\db1.mdb;Jet OleDb:"
Set conn = CreateObject("ADODB.Connection")
With conn
.ConnectionString = ConString
.Open
End With
End Sub
还是没有反应!
我建了个子程序 :CC :代码如下:
Private Sub cc()
If Rst.RecordCount > 0 Then
n.Text = Rst.Fields("n").Value & ""
Text1(0).Text = Rst.Fields("zy1").Value & ""
。。。
。。。
。。。
End Sub
初步解决了代码臃肿问题!
另外,列表框问题也得到了解决!
Private Sub Combo1_Click()
If Combo1.Text = "一月" Then
Rst.Open "Select * From pzfx1", conn, adOpenKeyset, adLockPessimistic, adCmdText
Call cc
End If
If Combo1.Text = "二月" Then
Rst.Open "Select * From pzfx2", conn, adOpenKeyset, adLockPessimistic, adCmdText
Call cc
End If
If Combo1.Text = "三月" Then
Rst.Open "Select * From pzfx3", conn, adOpenKeyset, adLockPessimistic, adCmdText
Call cc
End If
。。。
。。。
End Sub