标题:如何把COMBO1控件里的LIST一月、二月、三月、四月与DB1里的F1表、F2表、F3表 ...
取消只看楼主
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
结帖率:84.62%
 问题点数:0 回复次数:11 
如何把COMBO1控件里的LIST一月、二月、三月、四月与DB1里的F1表、F2表、F3表。。。
如何把COMBO1控件里的LIST一月、二月、三月、四月与DB1里的F1表、F2表、F3表。。。。对应打开呢?
如何设置呢?

我的代码很简单:

Private Sub Combo1_Change()

if combo1.additem="一月" then
Rst.CursorLocation = adUseClient
Rst.Open "Select * From lrb", conn, adOpenKeyset, adLockPessimistic
If Rst.RecordCount > 0 Then

Text1(1).Text = Rst.Fields("hhh46").Value
.....
.....
end if

我只在COMBO1控件里的LIST属性设置为:一月、二月、三月、四月,
其余没有做更动了!
执行后,没有反应!
搜索更多相关主题的帖子: COMBO1控件 F1表 F2表 F3表 LIST 
2007-09-07 16:00
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
得分:0 

Private Sub Combo1_Change()
If Combo1.AddItem = "一月" Then
Rst.CursorLocation = adUseClient
Rst.Open "Select * From f1", conn, adOpenKeyset, adLockPessimistic


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 & ""
...
...

Private Sub Form_Load()

Dim ConString As String
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属性设置为:一月、二月、三月、四月,
其余没有做更动了!
执行后,没有反应!

2007-09-07 19:14
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
得分:0 

仅仅在它的list里添加的“一月”、“二月”。。。

其余未作更改!
执行时,Combo1下拉框便自动出来这12个月!

ItemData属性没有动!为空!

2007-09-07 19:23
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
得分:0 
没有买到合适的书,书上面介绍太过于简单了!

许多控件的属性的名称、意义、设置介绍得很简单,所以还是不甚了了!

还有,ACCESS数据库的关系这节内容,介绍得也非常简单!

DataGrid与Adoc之间的调用!我是经过了无数的调试才找到了正确的属性设置!书上根本就看不见!

今天书在单位,没有带回来,

本来,Combo1的控件使用应该不难解决的!
2007-09-07 20:40
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
得分:0 
Combo1的Text、List、ItemData这三个属性怎么使用?我不太清楚!Combo1。AddItem呢?

我以前做过Combo1。List男,女,0,1

用A
2007-09-07 20:45
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
得分:0 
最笨的办法,就是干脆建12个COMMAND控件!这最简单!
我只好用了这办法解决了问题!
2007-09-07 20:48
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
得分:0 

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个月。其余未作改动!

2007-09-08 17:21
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
得分:0 

改:

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

还是没有反应!

2007-09-08 17:25
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
得分:0 

我建了个子程序 :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

2007-09-11 20:31
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
得分:0 
什么意思?

能详细解释下么?
2007-09-11 21:02



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-168415-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022695 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved