Can anybody help me out i'm having a few problems with my address book. The problem is on frmDisplay can you help me display each record in a list view with everything in it. I have also attached my code for you to take a look at
Printable View
Can anybody help me out i'm having a few problems with my address book. The problem is on frmDisplay can you help me display each record in a list view with everything in it. I have also attached my code for you to take a look at
Took only a minute to update the cmdDisplay_Click() event.
EDIT: Oh, a solution was already provided.
I'm having a problem with the delete code can anyone help me please i ahve attached my project aswell.
VB Code:
Private Sub cmdDelete_Click() Dim lngIndex As Long Dim i As Long If Admin = False Or User = True Then MsgBox "Sorry, unfortunately only someone with Administrator Access can perform that operation. Please contact your administrator for further queries." Else If vbNo = MsgBox("Are you sure?", vbYesNo + vbQuestion, "About to Delete This address") Then Exit Sub End If For lngIndex = 1 To Number - 1 With AddressBook(lngIndex) .fullname = AddressBook(lngIndex + 1).fullname .address = AddressBook(lngIndex + 1).address .town = AddressBook(lngIndex + 1).town .postcode = AddressBook(lngIndex + 1).postcode .dob = AddressBook(lngIndex + 1).dob .house = AddressBook(lngIndex + 1).house .mobile = AddressBook(lngIndex + 1).mobile End With Next Kill FileName Number = Number - 1 Open FileName For Output As #1 For i = 1 To Number ' - 1 With AddressBook(i) Write #1, .fullname Write #1, .address Write #1, .town Write #1, .postcode Write #1, .dob Write #1, .house Write #1, .mobile End With Next i Close #1 'new With AddressBook(1) Text1.Text = .fullname Text2.Text = .address Text3.Text = .town Text4.Text = .postcode Text5.Text = .dob Text6.Text = .house Text7.Text = .mobile End With End If End Sub
Your always deleting the first item in the array cause your starting your "shift" loop there.
VB Code:
Public Sub ShiftDown(ByVal currpos As Long) Dim i As Long If currpos < LBound(AddressBook) Or currpos > UBound(AddressBook) For i = currpos To UBound(AddressBook) - 1 'start shift at current position With AddressBook(i) .fullname = AddressBook(i + 1).fullname .address = AddressBook(i + 1).address .town = AddressBook(i + 1).town .postcode = AddressBook(i + 1).postcode .dob = AddressBook(i + 1).dob .house = AddressBook(i + 1).house .mobile = AddressBook(i + 1).mobile End With Next ReDim Preserve AddressBook(UBound(AddressBook) - 1) End Sub
How would i get it to delete the record that i choose instead of deleting the first one.?
You pass currpos to the function I gave you, its an array index where you want to start the deletion.
If your indices for AddressBook() were 0,1,2,3,4,5 or lower bound zero and upper bound 5 then calling ShiftDown(2) will result with 0,1,3,4,5 (these are previous index values).
You can then go on as you did before, killing the previous copy of the file and creating a new one from AddressBook().
Im lost now can you put it in to the project
VB Code:
Private Sub cmdDelete_Click() Dim lngIndex As Long Dim i As Long If Admin = False Or User = True Then MsgBox "Sorry, unfortunately only someone with Administrator Access can perform that operation. Please contact your administrator for further queries." Else If vbNo = MsgBox("Are you sure?", vbYesNo + vbQuestion, "About to Delete This address") Then Exit Sub End If 'For lngIndex = 1 To Number - 1 ' With AddressBook(lngIndex) ' .fullname = AddressBook(lngIndex + 1).fullname ' .address = AddressBook(lngIndex + 1).address ' .town = AddressBook(lngIndex + 1).town ' .postcode = AddressBook(lngIndex + 1).postcode ' .dob = AddressBook(lngIndex + 1).dob ' .house = AddressBook(lngIndex + 1).house ' .mobile = AddressBook(lngIndex + 1).mobile ' End With 'Next 'Are you still using nextrec variable for storing array index reference? If so... Call ShiftDown(nextrec - 1) Kill FileName Number = Number - 1 Open FileName For Output As #1 For i = 1 To Number ' - 1 With AddressBook(i) Write #1, .fullname Write #1, .address Write #1, .town Write #1, .postcode Write #1, .dob Write #1, .house Write #1, .mobile End With Next i Close #1 'new With AddressBook(1) Text1.Text = .fullname Text2.Text = .address Text3.Text = .town Text4.Text = .postcode Text5.Text = .dob Text6.Text = .house Text7.Text = .mobile End With End If End Sub Public Sub ShiftDown(ByVal currpos As Long) Dim i As Long If currpos < LBound(AddressBook) Or currpos > UBound(AddressBook) For i = currpos To UBound(AddressBook) - 1 'start shift at current position With AddressBook(i) .fullname = AddressBook(i + 1).fullname .address = AddressBook(i + 1).address .town = AddressBook(i + 1).town .postcode = AddressBook(i + 1).postcode .dob = AddressBook(i + 1).dob .house = AddressBook(i + 1).house .mobile = AddressBook(i + 1).mobile End With Next ReDim Preserve AddressBook(UBound(AddressBook) - 1) End Sub
this part of the code comes up red.
Compile Error
Syntax error
VB Code:
If currpos < LBound(AddressBook) Or currpos > UBound(AddressBook)
Forgot the Then part
If currpos < LBound(AddressBook) Or currpos > UBound(AddressBook) Then Exit Sub
Problem now fixed thank you
Do you know howe i can get it so on the list view it shows me how many records there is in a label.
Quote:
Originally Posted by Jamie_Garland
VB Code:
Label.Caption = UBound(AddressBook) + 1
Please don't PM me asking for help in your thread.
See if i was to double click on the listview how would i beable to show the record thats been clicked on.
Store the array index into listitem.tag
So on click/dblclick you can access the array index through listview1.selecteditem.tag
im lost now
When your adding items to the listview also include .tag
VB Code:
Dim lstNew As ListItem Set lstNew = ListView1.ListItems.Add lstNew.Text = AddressBook(lngIndex + 1).fullnam lstNew.Tag = lngIndex + 1 'the array index of AddressBook() entry
So on double click, the selected listitem supplies the index
MsgBox AddressBook(Val(ListView1.SelectedItem.Tag)).fullnam
This is my ListView code.
VB Code:
Option Explicit Private Sub cmdBack_Click() Unload Me End Sub Private Sub cmdClose_Click() Unload Me End Sub Private Sub cmdNext_Click() If lvwDisplay.SelectedItem.Index < lvwDisplay.ListItems.Count Then lvwDisplay.ListItems(lvwDisplay.SelectedItem.Index + 1).Selected = True Else lvwDisplay.ListItems(1).Selected = True End If lvwDisplay.SelectedItem.EnsureVisible lvwDisplay.SetFocus End Sub Private Sub cmdPrev_Click() If lvwDisplay.SelectedItem.Index < lvwDisplay.ListItems.Count Then lvwDisplay.ListItems(lvwDisplay.SelectedItem.Index - 1).Selected = True Else lvwDisplay.ListItems(1).Selected = True End If lvwDisplay.SelectedItem.EnsureVisible lvwDisplay.SetFocus End Sub Private Sub Form_Load() Label1.Caption = UBound(AddressBook) & " Players In The Database " CenterMe Me Dim lstAdd As ListItem Dim i As Long With lvwDisplay .AllowColumnReorder = False .FullRowSelect = True .HideColumnHeaders = False .HideSelection = False .LabelEdit = lvwManual .MultiSelect = False .Sorted = True .SortKey = 0 .View = lvwReport .ColumnHeaders.Clear .ColumnHeaders.Add , , "FULL NAME", 2000 .ColumnHeaders.Add , , "FULL ADDRESS", 3000 .ColumnHeaders.Add , , "TOWN", 1200 .ColumnHeaders.Add , , "POST CODE", 1500 .ColumnHeaders.Add , , "DATE OF BIRTH", 2000 .ColumnHeaders.Add , , "HOUSE NUMBER", 2000 .ColumnHeaders.Add , , "MOBILE NUMBER", 2000 .ListItems.Clear For i = LBound(AddressBook) To UBound(AddressBook) Set lstAdd = .ListItems.Add lstAdd.Text = AddressBook(i).fullname lstAdd.SubItems(1) = AddressBook(i).address lstAdd.SubItems(2) = AddressBook(i).town lstAdd.SubItems(3) = AddressBook(i).postcode lstAdd.SubItems(4) = AddressBook(i).dob lstAdd.SubItems(5) = AddressBook(i).mobile lstAdd.SubItems(6) = AddressBook(i).house Next End With End Sub Private Sub lvwDisplay_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader) If lvwDisplay.SortKey = ColumnHeader.Index - 1 Then If lvwDisplay.SortOrder = lvwAscending Then lvwDisplay.SortOrder = lvwDescending Else lvwDisplay.SortOrder = lvwAscending End If Else lvwDisplay.SortKey = ColumnHeader.Index - 1 End If End Sub
So what's your existing code for double click? We don't even have an idea what you mean by showing the record.. showing in another form? Showing in textboxes? etc?
You have to learn to be more informative and don't expect someone will always do most of the coding for you.
I want it to show on another form im sorry i should have been more informative in the future.
VB Code:
Dim oFrm As New YourShowForm Load oFrm With AddressBook(Val(lvwDisplay.SelectedItem.Tag)) oFrm.txtFullName.Text = .fullnam oFrm.txtFullName.Tag = Val(lvwDisplay.SelectedItem.Tag) 'in case you need to know array index in other form oFrm.txtAddress.Text = .address 'etc etc End With
What do i do to get it on the new form.
Do i do this first.
VB Code:
Private Sub lvwDisplay_DblClick() frmPeople.Show End Sub
VB Code:
[b]Private Sub lvwDisplay_DblClick()[/b] Dim oFrm As New YourShowForm Load oFrm With AddressBook(Val(lvwDisplay.SelectedItem.Tag)) oFrm.txtFullName.Text = .fullnam oFrm.txtFullName.Tag = Val(lvwDisplay.SelectedItem.Tag) 'in case you need to know array index in other form oFrm.txtAddress.Text = .address 'etc etc End With [b]oFrm.Show End Sub[/b]
I'll test this code as soon as i get home.
When i try to double click on one of the records i get an error.
Run-time error '9':
Subscript out of range
here is the code.
This part is the where is highlighted
With AddressBook(Val(lvwDisplay.SelectedItem.Tag))
VB Code:
Private Sub lvwDisplay_DblClick() Dim oFrm As New oFrm Load oFrm With AddressBook(Val(lvwDisplay.SelectedItem.Tag)) oFrm.txtFirst.Text = .fullname oFrm.txtFirst.Tag = Val(lvwDisplay.SelectedItem.Tag) End With oFrm.Show End Sub
* sigh * This is getting frustrating.
You will get that error if you didn't assign anything to the Tag property, so the Val() function will return zero if Tag has no value... and you declared "Option Base 1" so your arrays have no zero index.. hence "subscript out of range"
You can also get that error if you assigned wrong indices to the Tag property due to wrong arithmetic.
Now, DID you include, during adding listitems to the listview, saving the array index to the Tag property like I told you a couple of posts back?!?!?
Or did you just copy paste post #25 disregarding the instruction to initialize values for the Tag property of the listitems in the listview?
This is the code i use below.
VB Code:
Option Explicit Private Sub cmdBack_Click() Unload Me End Sub Private Sub cmdClose_Click() Unload Me End Sub Private Sub cmdNext_Click() If lvwDisplay.SelectedItem.Index < lvwDisplay.ListItems.Count Then lvwDisplay.ListItems(lvwDisplay.SelectedItem.Index + 1).Selected = True Else lvwDisplay.ListItems(1).Selected = True End If lvwDisplay.SelectedItem.EnsureVisible lvwDisplay.SetFocus End Sub Private Sub cmdPrev_Click() If lvwDisplay.SelectedItem.Index < lvwDisplay.ListItems.Count Then lvwDisplay.ListItems(lvwDisplay.SelectedItem.Index - 1).Selected = True Else lvwDisplay.ListItems(1).Selected = True End If lvwDisplay.SelectedItem.EnsureVisible lvwDisplay.SetFocus End Sub Private Sub Form_Load() Label1.Caption = UBound(AddressBook) & " Players In The Database " CenterMe Me Dim lstAdd As ListItem Dim i As Long With lvwDisplay .AllowColumnReorder = False .FullRowSelect = True .HideColumnHeaders = False .HideSelection = False .LabelEdit = lvwManual .MultiSelect = False .Sorted = True .SortKey = 0 .View = lvwReport .ColumnHeaders.Clear .ColumnHeaders.Add , , "FULL NAME", 2000 .ColumnHeaders.Add , , "FULL ADDRESS", 3000 .ColumnHeaders.Add , , "TOWN", 1200 .ColumnHeaders.Add , , "POST CODE", 1500 .ColumnHeaders.Add , , "DATE OF BIRTH", 2000 .ColumnHeaders.Add , , "HOUSE NUMBER", 2000 .ColumnHeaders.Add , , "MOBILE NUMBER", 2000 .ListItems.Clear For i = LBound(AddressBook) To UBound(AddressBook) Set lstAdd = .ListItems.Add lstAdd.Text = AddressBook(i).fullname lstAdd.SubItems(1) = AddressBook(i).address lstAdd.SubItems(2) = AddressBook(i).town lstAdd.SubItems(3) = AddressBook(i).postcode lstAdd.SubItems(4) = AddressBook(i).dob lstAdd.SubItems(5) = AddressBook(i).mobile lstAdd.SubItems(6) = AddressBook(i).house Next End With End Sub Private Sub lvwDisplay_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader) If lvwDisplay.SortKey = ColumnHeader.Index - 1 Then If lvwDisplay.SortOrder = lvwAscending Then lvwDisplay.SortOrder = lvwDescending Else lvwDisplay.SortOrder = lvwAscending End If Else lvwDisplay.SortKey = ColumnHeader.Index - 1 End If End Sub Private Sub lvwDisplay_DblClick() Dim oFrm As New oFrm Load oFrm With AddressBook(Val(lvwDisplay.SelectedItem.Tag)) oFrm.txtFirst.Text = .fullname oFrm.txtFirst.Tag = Val(lvwDisplay.SelectedItem.Tag) End With oFrm.Show End Sub
God, can't you do anything besides copying and pasting? We do your code, we even do the debugging for you.
And now just understanding instructions, which was explained again and again, to add one line you can't do?!?
VB Code:
.ListItems.Clear For i = LBound(AddressBook) To UBound(AddressBook) Set lstAdd = .ListItems.Add lstAdd.Text = AddressBook(i).fullname [b]lstAdd.Tag = i[/b] lstAdd.SubItems(1) = AddressBook(i).address lstAdd.SubItems(2) = AddressBook(i).town lstAdd.SubItems(3) = AddressBook(i).postcode lstAdd.SubItems(4) = AddressBook(i).dob lstAdd.SubItems(5) = AddressBook(i).mobile lstAdd.SubItems(6) = AddressBook(i).house Next
That's it. that's my last post in this thread.
Thank you sorted now.