i need another help regarding listview.
I have a listview and command buttons like cmdAdd, cmdSave, cmdEdit, and cmdDelete. When I click cmdAdd, it will validate flight number. And if it is accepted, cmdSave will be enabled. When cmdSave is clicked, the system will add a new flight. I wanted to have the newly added record to be seen in the lisview right after I clicked cmdSave. I have tried to use lvTariff.Refresh but nothing happens. The newly added record only appears when I stop then run the program again. Below is my code:
CODE
Private Sub cmdSave_Click()
Dim AddNewFlight As String
If txtFlightNo.Enabled = False Then
'check blank fields
If VerEntry Then
MsgBox "Please fill up the fields you left blank.", vbInformation, "Incomplete information detected..."
Else
'access to database(save to tblEmpinfo)
AddNewFlight = "insert into TariffAP ([FL_NO],[ROUTE],[Y],[S],[Q],[V], [B], [X],[K],[E],[T],[U], [M], [L],[PH],[YQ]) values ('" & txtFlightNo & "' , '" & txtRoute & "' , '" & txtBCC(0) & "' , '" & txtBCC(1) & "' , '" & txtBCC(2) & "' , '" & txtBCC(3) & "' , '" & txtBCC(4) & "', '" & txtBCC(5) & "', '" & txtBCC(6) & "' , '" & txtBCC(7) & "' , '" & txtBCC(8) & "' , '" & txtBCC(9) & "' , '" & txtBCC(10) & "', '" & txtBCC(11) & "', '" & txtPH & "', '" & txtYQ & "' ) "
Set NewFlightRec = myConn.Execute(AddNewFlight)
'access to database(save to tblCompany)
'CompInfoNew = "insert into [tblCompany] ([EMPID],[POSITION]) values ('" & txtEmpID & "', '" & cboPosition & "')"
'Set CompInfo = myConn.Execute(CompInfoNew)
'determine success of adding
MsgBox "The new record has been added succesfully.", vbInformation, "Adding new record..."
enableCMDsSave
lvTariff.Refresh
End If
End If
End Sub
It was also the same thing I wanted to happen when I delete and edit records. When I click cmdDelete and the record was successfully deleted, I wanted that that record will be deleted from the listview. Same as with editing records, I wanted to see that the edited record has changed in the listview right after I click cmdUpdate. Below are my codes for cmdDelete and cmdEdit:
CODE
Private Sub cmdDelete_Click()
'#1. declaration of variables
Dim DelRec As String
'#2. delete employee
DelRec = MsgBox("Are you sure you want to delete record?", vbQuestion + vbYesNo, "Deleting record...")
If DelRec = vbYes Then
Set DelFlightRec = myConn.Execute("Delete * from TariffAP where FL_NO=" & Str(Val(txtFlightNo.Text)))
MsgBox "Record has been deleted!", vbInformation, "Deleted record..."
'clear fields
ClearTextBox
txtFlightNo = ""
lvTariff.Refresh
Else
Me.Refresh
End If
End Sub
Private Sub cmdEdit_Click()
Dim UpdateFlight As String
If cmdEdit.Caption = "&EDIT" Then
DisableCMDsEdit
EnableTextBoxADD
txtFlightNo.Enabled = True
lvTariff.Enabled = False
Else
If VerEntry Then
MsgBox "Please fill up the blank fields left.", vbInformation, "Verifying..."
Else
UpdateFlight = "update TariffAP set ROUTE='" & txtRoute & "', Y='" & txtBCC(0) & "',S ='" & txtBCC(1) & "', Q='" & txtBCC(2) & "', V ='" & txtBCC(3) & "' where FL_NO=" & Str(Val(txtFlightNo))
Set UpdateFlightRec = myConn.Execute(UpdateFlight)
MsgBox "Record successfully updated.", vbInformation, "Updating..."
cmdEdit.Caption = "EDIT"
enableCMDsSave
cmdSave.Enabled = True
lvTariff.Enabled = True
DisableTextBoxAdd
End If
End If
End Sub
thanks in advance!