# Re: Answer fot " DataCombo2资料来源由DataCombo来选择"

Posted by Spencer Yang on April 28, 1999 at 07:12:21:

In Reply to: 请教 DataCombo 的问题 材! posted by gg on April 27, 1999 at 17:18:04:

'=========================================================================================
' File: frmBusinessItem.frm
'
' Copyright:
'
' Date Created: 1999/04/28
'
' Initial Author: Spencer Yang
'
' Purpose: 假设 DataCombo1之资料来源为县巿, DataCombo2之资料来源为乡镇
' 使用者点选 DataCombo1后, 比如台北县, DataCombo2的资料来源会随之异动, 比如
' 只有出现板桥市、永和巿...
'
' Entry Points:
'
' Dependencies:
'
' Issues:
'
' Method:
'=========================================================================================
Option Explicit

' ... 表单
'
' adodc1:县巿
' adodc2:乡镇(其中connectString, CommandType,RecordSource为空)
' DataCombo1:县巿名称
' DataCombo2:乡镇名称
' Text1:县巿编号
' Text2:乡镇编号

Private Sub DataCombo1_Click(Area As Integer)
' 传入县巿编号
Text1.Text = DataCombo1.BoundText
End Sub

Private Sub DataCombo1_LostFocus()
DoQuery
End Sub

Private Sub DataCombo2_Click(Area As Integer)
Text2.Text = DataCombo2.BoundText
End Sub

Sub DoQuery()
Dim strConnectionString As String ' 连接字串变数
Dim strCountyNo As String ' 县巿编号变数
Dim strSQL As String ' SQL 字串变数
On Error Resume Next
'------------------------------------------------
' D0 资料控制项
'------------------------------------------------
strConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=C:\Utility\utlAddress.mdb"
strCountyNo = Text1.Text
strSQL = "SELECT 乡镇编号, 乡镇名称, 县巿编号 " _
& "FROM tbl3_Town " _
& "WHERE 县巿编号=" & Chr(39) & strCountyNo & Chr(39) _
& " ORDER BY 乡镇编号 "
With Adodc2
.ConnectionString = strConnectionString
.CommandType = adCmdText
.RecordSource = strSQL
.Refresh
End With
End Sub

Follow Ups: