为什么定义public变量从一个过程到另一个过程就失效?
zl13 2004-11-27 11:28:11 Public theText As Variant
Public theValue As Variant
Dim Conn As Object
Dim Rs As Object
Const cnConnStr = "DSN=LocalServer;uid=sa;pwd=19821113;Database=pubs"
Const adCmdText = 1
Const RecordsAffected = 60
Private Sub clean_Click()
End Sub
Private Sub execute_Click()
End Sub
Private Sub regtype_Change()
Stop
Dim index As Integer
MsgBox regtype.ListIndex + 1
index = regtype.ListIndex + 1
theValue (index)
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set Conn = CreateObject("Adodb.Connection")
Conn.Open cnConnStr
CommandText = "Select * from authors"
Set Rs = Conn.execute(CommandText, RecordsAffected, adCmdText)
RowNum = 2
Stop
If ListIndex <> "" Or ListIndex <> 0 Then
MsgBox theValue(ListIndex)
Else
If Not Rs.EOF Then
While Not Rs.EOF
For Colnum = 0 To Rs.Fields.Count - 1
ActiveSheet.Cells(RowNum, 2) = Rs("au_lname").Value
theText = Rs("au_fname")
theValue = Rs("au_id")
regtype.AddItem Rs("au_lname")
Next
Rs.MoveNext
RowNum = RowNum + 1
Wend
End If
End If
End Sub
theValue和theText只要出了Worksheet_SelectionChange就会对象无效,各位高手又什么好办法么