Comment accepted as answer
Main Topics
Browse All TopicsI am building an application using a tree view to access a sequential file on the" c:\myproject\Hotel.txt"
(not familiar with accessing access)
On my form I have a tree view - a frame with three text boxes(Country City Hotel .) and cmdadd where I can successfully add nodes at runtime and save them.
Then I have frmAdd where there are all the details of the hotel
Address phone etc etc in text boxes.
What I would like to do is
After inputting the info in frm Add I would like this info to go the Hotel that I want.
And whenever I click the hotel (node) I would like the info to be displayed in
List view
I have been told that I should add an index , and that treeview have keys.
I cannot figure it out and is driving me MAD.
Has anybody got a small example ? Or is it possible to email my small project.
Thanks everybody.
Gabriel
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: mkmccrearyPosted on 2000-06-06 at 16:05:12ID: 2901922
Here is the code for the main form. I also have the whole project if you would like it e-mailed to you. Now, it doesn't take into account concurrency. Instead of using a form level variable to hold the last hotel key you would want to use a file to hold the key if it is going to be a multi-user app. Check this out and if you want leave me your e-mail address as a comment and I will e-mail the whole project.
(, "K" & Key, Name)
ar
tvwHotels. SelectedIt em.Key).Se lected = True
Option Explicit
Private mlngLastKey As Long
Private Function TreeviewAdd(ByVal Key As Long, ByVal Name As String, ByVal Address As String, ByVal Phone As String) As Boolean
Me.tvwHotels.Nodes.Add , , "K" & Key, Name
End Function
Private Function ListviewAdd(ByVal Key As Long, ByVal Name As String, ByVal Address As String, ByVal Phone As String) As Boolean
Dim oListItem As MSComctlLib.ListItem
Set oListItem = Me.lvwHotels.ListItems.Add
With oListItem
.ListSubItems.Add Text:=Address
.ListSubItems.Add Text:=Phone
End With
Set oListItem = Nothing
End Function
Private Function AddToFile(ByVal Key As Long, ByVal Name As String, ByVal Address As String, ByVal Phone As String) As Boolean
Dim intFileHandle As Long
intFileHandle = FreeFile
Open App.Path & "\Hotels.txt" For Append Access Write Lock Read Write As #intFileHandle
Write #intFileHandle, Key, Name, Address, Phone
Close #intFileHandle
End Function
Private Sub cmdAdd_Click()
Dim oForm As frmAdd
Set oForm = New frmAdd
With oForm
.Show vbModal
If Not .Cancelled Then
mlngLastKey = mlngLastKey + 1
AddToFile mlngLastKey, .txtName, .txtAddress, .txtPhone
TreeviewAdd mlngLastKey, .txtName, .txtAddress, .txtPhone
ListviewAdd mlngLastKey, .txtName, .txtAddress, .txtPhone
End If
End With
Unload oForm
End Sub
Private Sub Form_Load()
Dim intFileHandle As Long
Dim lngHotelKey As Long
Dim strHotelName As String
Dim strHotelAddress As String
Dim strHotelPhone As String
On Error GoTo ErrorHandler
mlngLastKey = 0
Me.lvwHotels.ListItems.Cle
Me.tvwHotels.Nodes.Clear
intFileHandle = FreeFile
Open App.Path & "\Hotels.txt" For Input Access Read As #intFileHandle
While Not EOF(intFileHandle)
Input #intFileHandle, lngHotelKey, strHotelName, strHotelAddress, strHotelPhone
TreeviewAdd lngHotelKey, strHotelName, strHotelAddress, strHotelPhone
ListviewAdd lngHotelKey, strHotelName, strHotelAddress, strHotelPhone
mlngLastKey = lngHotelKey
Wend
ExitSub:
Close #intFileHandle
Exit Sub
ErrorHandler:
Select Case Err.Number
Case 53
' File Not Found - Do nothing
Case Else
MsgBox Err.Number & vbTab & Err.Description, vbOKOnly + vbExclamation, "Error "
End Select
Resume ExitSub
End Sub
Private Sub tvwHotels_Click()
Me.lvwHotels.ListItems(Me.
Me.lvwHotels.SetFocus
End Sub
Enjoy,
mkmccreary