|
-
Aug 19th, 2011, 09:44 AM
#1
Thread Starter
Member
Please Help. Need INfo
Hi Guys, Need Help With This
I have got a listview that shows the information loaded from a database.. running through Ado Data Control.
I can get new items added fine, and updating the database is good.. but when it comes to removeing the selected item, it always deletes the first item and not the selected.
I even set the program to set 4 labels with the information of the selected item and then ado run it through them. It finds the first label and checks the rest of the fields against labels 2 - 4. And it always finds it... but then removes the first item in the list??
I even tried it to just remove it from the information on label 1... i set two items on the list.. one said wages, other said benefits... i clicked on benefits and it deleted wages??
My Coding is very very bad, but i just want to get it to work for now, then i will cut it down and make it neat. Code is below: (Note:Income1 = Listview
)
vb Code:
Private Sub Command3_Click()
If Adodc1.Recordset.BOF = False Then Adodc1.Recordset.MoveFirst
Label1.Caption = Income1.SelectedItem
Label2.Caption = Income1.SelectedItem.SubItems(1)
Label3.Caption = Income1.SelectedItem.SubItems(2)
Label4.Caption = Income1.SelectedItem.SubItems(3)
Adodc1.Recordset.Find "Income = '" & Label1.Caption & "'"
If Adodc1.Recordset.Fields!Date = Label2.Caption _
And Adodc1.Recordset.Fields!Amount = Label3.Caption _
And Adodc1.Recordset.Fields!Frequency = Label4.Caption Then
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveFirst
Else
MsgBox "Not Item Found", vbOKOnly + vbExclamation, "Error27"
End If
End Sub
I choose to post it here as i do not know if it is a listview problem or a database error?
Last edited by Hack; Aug 19th, 2011 at 09:59 AM.
Reason: Added Highlight Tags and some indenting
-
Aug 19th, 2011, 10:53 AM
#2
Re: Please Help. Need INfo
Try the next:
Remove from the 'Command3_Click' event the next code
Code:
Label1.Caption = Income1.SelectedItem
Label2.Caption = Income1.SelectedItem.SubItems(1)
Label3.Caption = Income1.SelectedItem.SubItems(2)
Label4.Caption = Income1.SelectedItem.SubItems(3)
In the 'Income1_ItemClick' event write the next code
Code:
Label1.Caption = Item.Text
Label2.Caption = Item.SubItems(1)
Label3.Caption = Item.SubItems(2)
Label4.Caption = Item.SubItems(3)
I seems to me that you are not selecting the row in a proper way
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...
-
Aug 19th, 2011, 03:08 PM
#3
Thread Starter
Member
Re: Please Help. Need INfo
Thanks, will try it
-
Aug 26th, 2011, 07:03 AM
#4
Thread Starter
Member
Re: Please Help. Need INfo
Hey, jggtz
I did what you said and it says:
Complile Error:
Procedure Declaration does not match description of event or procedure having the same name.
Could you please advise.
-
Aug 26th, 2011, 08:44 AM
#5
Re: Please Help. Need INfo
Post the code and say in which line is the error
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...
-
Aug 26th, 2011, 08:51 AM
#6
Thread Starter
Member
Re: Please Help. Need INfo
Private Sub Income1_ItemClick()
Label1.Caption = Item.Text
Label2.Caption = Item.SubItems(1)
Label3.Caption = Item.SubItems(2)
Label4.Caption = Item.SubItems(3)
End Sub
Its in line 1 the error appears.. and yet whenever i click on the listview with this in the code, it automatically goes to this part of code??
-
Aug 26th, 2011, 09:13 AM
#7
Re: Please Help. Need INfo
In post #1 You did say that Income1 is a ListView control
The right syntax por the ItemClick event procedure is :
Code:
Private Sub Income1_ItemClick(ByVal Item As MSComctlLib.ListItem)
and You even don't have to write it, just select and use it
... and yes, the click on any row in the listview is the way to select the row that you're going to use a filter in the Find and Delete
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...
-
Aug 26th, 2011, 09:43 AM
#8
Thread Starter
Member
Re: Please Help. Need INfo
Ahh.
I done that and its selecting the listview item, and placing it in the labels... but it still deletes the first item?
Code 1:
Private Sub Income1_ItemClick(ByVal Item As MSComctlLib.ListItem)
Label1.Caption = Item.Text
Label2.Caption = Item.SubItems(1)
Label3.Caption = Item.SubItems(2)
Label4.Caption = Item.SubItems(3)
End Sub
Code 2:
Private Sub Command3_Click()
If Adodc1.Recordset.BOF = False Then Adodc1.Recordset.MoveFirst
Adodc1.Recordset.Find "Income = '" & Label1.Caption & "'"
If Adodc1.Recordset.Fields!Date = Label2.Caption And Adodc1.Recordset.Fields!Amount = Label3.Caption And Adodc1.Recordset.Fields!Frequency = Label4.Caption Then
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveFirst
Else
MsgBox "Not Item Found", vbOKOnly + vbExclamation, "Error27"
End If
End Sub
Any Ideas?
-
Aug 26th, 2011, 10:04 AM
#9
Re: Please Help. Need INfo
Try the next code
Code:
Private Sub Command3_Click()
If Adodc1.Recordset.BOF = False Then Adodc1.Recordset.MoveFirst
Adodc1.Recordset.Find "Income = '" & Label1.Caption & "'"
If Adodc1.EOF = False Then
If Adodc1.Recordset.Fields!Date = CDate(Label2.Caption) And _
Adodc1.Recordset.Fields!Amount = CDbl(Label3.Caption) And _
Adodc1.Recordset.Fields!Frequency = Label4.Caption Then
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveFirst
End If
Else
MsgBox "Not Item Found", vbOKOnly + vbExclamation, "Error27"
End If
End Sub
If the field "Amount" isn't double then change to right conversion
function, same applies to field Frequency
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...
-
Aug 26th, 2011, 11:54 AM
#10
Thread Starter
Member
Re: Please Help. Need INfo
Hey, done all that and it still deletes the first in the list.. and if i click command 3 without anything selected it also deletes one at a time from the top down??
But i can select the third and it will delete first and second before it deletes the third.
I will look through the rest of my Code.. it must be something in there causeing this.
Unless you have another idea?
-
Aug 26th, 2011, 01:05 PM
#11
Re: Please Help. Need INfo
and if i click command 3 without anything selected it also deletes one at a time from the top down
Code:
Private Sub Command3_Click()
If Trim(Label1.Caption) = "" Then
Exit Sub
End If
If Adodc1.Recordset.BOF = False Then
Adodc1.Recordset.MoveFirst
End If
Adodc1.Recordset.Find "Income = '" & Label1.Caption & "'"
If Adodc1.EOF = False Then
If Adodc1.Recordset.Fields!Date = CDate(Label2.Caption) And _
Adodc1.Recordset.Fields!Amount = CDbl(Label3.Caption) And _
Adodc1.Recordset.Fields!Frequency = Label4.Caption Then
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveFirst
Label1.Caption = ""
Label2.Caption = ""
Label3.Caption = ""
Label4.Caption = ""
End If
Else
MsgBox "Not Item Found", vbOKOnly + vbExclamation, "Error27"
End If
End Sub
Unless you have another idea
Post all your form's code and we'll see...
Last edited by jggtz; Aug 26th, 2011 at 01:14 PM.
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...
-
Aug 26th, 2011, 01:13 PM
#12
Thread Starter
Member
Re: Please Help. Need INfo
Hey, full code below... bit of a mess and prob sum bad programming... but its doing what i want so far.. apart from this deleteing issue.
Code:
Option Explicit
Dim I As Integer
Dim Incom As String
Dim Amoun As Currency
Dim Dat As Date
Dim Freq As String
Dim CurTot As Currency
Private Sub Command1_Click()
Adodc1.Recordset.AddNew
Incom = InputBox("Please Enter The Income Type." & Chr(13) & Chr(13) & "Example: Wages, Income Support, JSA etc..", "Add New Income")
Amoun = InputBox("Please Enter The Amount You Recieve" & Chr(13) & Chr(13) & "Format: ###.## etc..", "Add New Income")
Dat = InputBox("Please Enter The Date You Next Recieve This Payment" & Chr(13) & Chr(13) & "Format: ##/##/####", "Add New Income")
Freq = InputBox("Please Enter How Frequently You Recieve This Payment" & Chr(13) & "Use Code Below" & Chr(13) & Chr(13) & "D = Daily" & Chr(13) & "W = Weekly" & Chr(13) & "F = Every Two Weeks" & Chr(13) & "M = Monthly" & Chr(13) & "Y = Yearly", "Add New Income")
Label1.Caption = Incom
Label2.Caption = Dat
Label3.Caption = Amoun
If Freq = "D" Then Label4.Caption = "Daily"
If Freq = "W" Then Label4.Caption = "Weekly"
If Freq = "F" Then Label4.Caption = "Fort Nightly"
If Freq = "M" Then Label4.Caption = "Monthly"
If Freq = "Y" Then Label4.Caption = "Yearly"
Adodc1.Recordset.Update
Income1.ListItems.Clear
Form_Load
End Sub
Private Sub Command3_Click()
If Trim(Label1.Caption) = "" Then
Exit Sub
End If
If Adodc1.Recordset.BOF = False Then
Adodc1.Recordset.MoveFirst
End If
Adodc1.Recordset.Find "Income = '" & Label1.Caption & "'"
If Adodc1.Recordset.EOF = False Then
If Adodc1.Recordset.Fields!Date = CDate(Label2.Caption) And _
Adodc1.Recordset.Fields!Amount = CDbl(Label3.Caption) And _
Adodc1.Recordset.Fields!Frequency = Label4.Caption Then
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveFirst
Label1.Caption = ""
Label2.Caption = ""
Label3.Caption = ""
Label4.Caption = ""
End If
Else
MsgBox "Not Item Found", vbOKOnly + vbExclamation, "Error27"
End If
End Sub
Private Sub Command5_Click()
Dim lngIndex As Long
CurTot = 0
If Adodc1.Recordset.BOF = False Then Adodc1.Recordset.MoveFirst
For lngIndex = 1 To Adodc1.Recordset.RecordCount
CurTot = CurTot + Adodc1.Recordset.Fields!Amount
Label5.Caption = CurTot
If CurTot < 1000 Then
Label5.Caption = Format(Label5.Caption, "000.00")
Else
Label5.Caption = Format(Label5.Caption, "0000.00")
End If
Adodc1.Recordset.MoveNext
Next
£££Deck.Label1.Caption = "Income:"
£££Deck.Label1.Caption = £££Deck.Label1.Caption & " " & "£" & Label5.Caption
End Sub
Private Sub Form_Load()
Column_Setup
Data_Setup
End Sub
Private Sub Data_Setup()
If Adodc1.Recordset.RecordCount > 0 Then
I = 1
Adodc1.Recordset.MoveFirst
With Adodc1.Recordset
Do Until .EOF
Income1.ListItems.Add , , .Fields!Income
Income1.ListItems(I).SubItems(1) = .Fields!Date
Income1.ListItems(I).SubItems(2) = "£" & .Fields!Amount
Income1.ListItems(I).SubItems(3) = .Fields!Frequency
.MoveNext
I = I + 1
Loop
End With
Else
MsgBox "No Items In Database"
End If
End Sub
Private Sub Column_Setup()
With Income1
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "Income", .Width * 0.25
.ColumnHeaders.Add , , "Date", .Width * 0.25
.ColumnHeaders.Add , , "Amount", .Width * 0.25
.ColumnHeaders.Add , , "Frequency", .Width * 0.25
End With
End Sub
Private Sub Income1_ItemClick(ByVal Item As MSComctlLib.ListItem)
Label1.Caption = Item.Text
Label2.Caption = Item.SubItems(1)
Label3.Caption = Item.SubItems(2)
Label4.Caption = Item.SubItems(3)
End Sub
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|