J
Jeff
for your info - I'm a newbe.
Code is at the bottom.
Access dbase (each form ca. 10 KB) if my explanations are not enough
(probably they aren't).
-- access 97 - http://www.lokalny.net/Source97.zip
-- access 200 - http://www.lokalny.net/Source2000.zip
------
Im trying to change code - just trying to learn something. But nothing seems
to work.
Advice, hint ... anything would be helpfull.
Current situation:
-- after picking an option from a combo box (cboList), that option is being
shown in list box (lstInfo)
-- after clicking that new entry in (lstInfo) data is being distributed to
several text boxes.
What I'm trying to accomplish:
-- comboBox (cboList) - gone,
-- txtBox instead for entering a string and searching (say) xType column in
database
-- search results displayed in list box (lstInfo)
-- upon click on any of these results in list box (lstInfo) data from
recordset should be distributed to text boxes as it is now.
--------------
Here is code:
--------------
Option Explicit
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub cboList_Click(Index As Integer)
Dim t_Records As Long, t_Counter As Long
txtInfo(0).Text = ""
txtInfo(1).Text = ""
txtInfo(2).Text = ""
lblData(0).Caption = ""
'lblData(1).Caption = ""
lblData(2).Caption = ""
lstInfo.Clear
Label3.Visible = True
With rs
.Open "SELECT ID, xType, xSubType, SearchNote From tblSource Where
tblSource.xType = '" & cboList(0).Text & "' ORDER BY xSubType;"
If Not .EOF Then
lstInfo.Clear
t_Records = .RecordCount
For t_Counter = 1 To t_Records
lstInfo.AddItem .Collect(2) & " (" & Left(.Collect(3),
100) & ") ........"
lstInfo.ItemData(lstInfo.NewIndex) = .Collect(0)
.MoveNext
Next t_Counter
End If
If .State = adStateOpen Then .Close
End With
End Sub
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Form_Load()
On Error GoTo errH
Dim strPath As String
strPath = App.Path & "\Source.mdb"
With cn
.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath &
";Persist Security Info=False"
End With
With rs
.ActiveConnection = cn
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
End With
With tmData
.Interval = 123
.Enabled = True
End With
Exit Sub
errH:
If Err.Number = -2147467259 Then
MsgBox "Data file not found, ensure that the data file is in the " &
strPath & " directory " & vbCrLf & "This form will unload now", vbCritical,
"NBS Solutions"
Unload Me
Exit Sub
Else
Resume Next
End If
End Sub
Private Sub loadCAT()
With rs
.Open "SELECT DISTINCT xType From tblSource ORDER BY
xType;"
If Not .EOF Then
cboList(0).Clear
Do While Not .EOF
cboList(0).AddItem .Collect(0)
.MoveNext
Loop
End If
If .State = adStateOpen Then .Close
End With
End Sub
Private Sub loadInfo()
With rs
.Open "SELECT ID, xType, xSubType, xCode, xDeclarations,
xDescription, xNote, xRefrences FROM tblSource" _
& " WHERE ID =" & lstInfo.ItemData(lstInfo.ListIndex) & ""
If Not .EOF Then
txtInfo(0).Text = .Collect(4)
txtInfo(1).Text = .Collect(3)
txtInfo(2).Text = .Collect(6)
lblData(0).Caption = .Collect(5)
lblData(2).Caption = .Collect(7)
End If
If .State = adStateOpen Then .Close
End With
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
On Error Resume Next
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
Private Sub lstInfo_Click()
loadInfo
End Sub
Private Sub tmData_Timer()
tmData.Enabled = False
tmData.Interval = 0
loadCAT
End Sub
Code is at the bottom.
Access dbase (each form ca. 10 KB) if my explanations are not enough
(probably they aren't).
-- access 97 - http://www.lokalny.net/Source97.zip
-- access 200 - http://www.lokalny.net/Source2000.zip
------
Im trying to change code - just trying to learn something. But nothing seems
to work.
Advice, hint ... anything would be helpfull.
Current situation:
-- after picking an option from a combo box (cboList), that option is being
shown in list box (lstInfo)
-- after clicking that new entry in (lstInfo) data is being distributed to
several text boxes.
What I'm trying to accomplish:
-- comboBox (cboList) - gone,
-- txtBox instead for entering a string and searching (say) xType column in
database
-- search results displayed in list box (lstInfo)
-- upon click on any of these results in list box (lstInfo) data from
recordset should be distributed to text boxes as it is now.
--------------
Here is code:
--------------
Option Explicit
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub cboList_Click(Index As Integer)
Dim t_Records As Long, t_Counter As Long
txtInfo(0).Text = ""
txtInfo(1).Text = ""
txtInfo(2).Text = ""
lblData(0).Caption = ""
'lblData(1).Caption = ""
lblData(2).Caption = ""
lstInfo.Clear
Label3.Visible = True
With rs
.Open "SELECT ID, xType, xSubType, SearchNote From tblSource Where
tblSource.xType = '" & cboList(0).Text & "' ORDER BY xSubType;"
If Not .EOF Then
lstInfo.Clear
t_Records = .RecordCount
For t_Counter = 1 To t_Records
lstInfo.AddItem .Collect(2) & " (" & Left(.Collect(3),
100) & ") ........"
lstInfo.ItemData(lstInfo.NewIndex) = .Collect(0)
.MoveNext
Next t_Counter
End If
If .State = adStateOpen Then .Close
End With
End Sub
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Form_Load()
On Error GoTo errH
Dim strPath As String
strPath = App.Path & "\Source.mdb"
With cn
.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath &
";Persist Security Info=False"
End With
With rs
.ActiveConnection = cn
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
End With
With tmData
.Interval = 123
.Enabled = True
End With
Exit Sub
errH:
If Err.Number = -2147467259 Then
MsgBox "Data file not found, ensure that the data file is in the " &
strPath & " directory " & vbCrLf & "This form will unload now", vbCritical,
"NBS Solutions"
Unload Me
Exit Sub
Else
Resume Next
End If
End Sub
Private Sub loadCAT()
With rs
.Open "SELECT DISTINCT xType From tblSource ORDER BY
xType;"
If Not .EOF Then
cboList(0).Clear
Do While Not .EOF
cboList(0).AddItem .Collect(0)
.MoveNext
Loop
End If
If .State = adStateOpen Then .Close
End With
End Sub
Private Sub loadInfo()
With rs
.Open "SELECT ID, xType, xSubType, xCode, xDeclarations,
xDescription, xNote, xRefrences FROM tblSource" _
& " WHERE ID =" & lstInfo.ItemData(lstInfo.ListIndex) & ""
If Not .EOF Then
txtInfo(0).Text = .Collect(4)
txtInfo(1).Text = .Collect(3)
txtInfo(2).Text = .Collect(6)
lblData(0).Caption = .Collect(5)
lblData(2).Caption = .Collect(7)
End If
If .State = adStateOpen Then .Close
End With
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
On Error Resume Next
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
Private Sub lstInfo_Click()
loadInfo
End Sub
Private Sub tmData_Timer()
tmData.Enabled = False
tmData.Interval = 0
loadCAT
End Sub