My program is a simple inventory system. It has a 3 main form which are Main,Add and Edit form
Error: Every time I tried to select an item from the listview and press the Edit it shows an error.
Things I did before I get an Error;
* I change the Field Name order of the Database from IDNumber(Primary Key)-Owner-Status-Department-Acquired-Released into Owner(Primary Key)-IDNumber
* I did check the column header order of Listview on its properties. And I think its fine
* I did check the codes of modules and I think its fine
* And also I did check the codes of Edit form and I think it is also fine.
Please help me.
Here are the codes for Main and for Edit form and also for the Module
Main Form
Private Sub refreshDataSearch Code:
Private Sub refreshDataSearch() Dim Itmx As ListItem EmployeeMain.Listview.ListItems.Clear While Not FindRs.EOF = True Set Itmx = EmployeeMain.Listview.ListItems.Add(, , FindRs.Fields("Owner")) Itmx.SubItems(1) = FindRs.Fields("IDNumber") Itmx.SubItems(2) = FindRs.Fields("Status") Itmx.SubItems(3) = FindRs.Fields("Department") Itmx.SubItems(4) = FindRs.Fields("Acquired") Itmx.SubItems(5) = FindRs.Fields("Released") FindRs.MoveNext Wend End Sub
Private Sub editite_Click Code:
Private Sub editid_Click() If txtMonitor.Text = vbNullString Then MsgBox "Have you selected I.D. from Catalog? ", vbExclamation, "Edit an I.D." Exit Sub: End If EmployeeUpdate.txtIDNumber.Enabled = False EmployeeUpdate.txtIDNumber.Text = Me.txtMonitor.Text EmployeeUpdate.Show vbModal End Sub
Edit/Update Form
Private Sub Form_Activate Code:
Private Sub Form_Activate() FindRecordset "Select * From Finder Where Owner = '" & txtOwner & "';" If Not FindRs.BOF = True Or FindRs.EOF = True Then txtIDNumber.Text = FindRs.Fields("IDNumber") txtAcquired.Text = FindRs.Fields("Acquired") txtReleased.Text = FindRs.Fields("Released") cboDepartment.Text = FindRs.Fields("Department") cboStatus.Text = FindRs.Fields("Status") Else End If End Sub
Private Sub cmdUpdate_Click Code:
Private Sub cmdUpdate_Click() On Error GoTo errorupdate If txtOwner.Text = vbNullString Or txtIDNumber.Text = vbNullString Or cboStatus.ListIndex = -1 Then MsgBox "Please fill the required fields in order to save.", vbExclamation, "Saving Status" Exit Sub: End If executeQuery "UPDATE Finder SET Owner = '" & txtOwner & "', Acquired = '" & txtAcquired & "', Released = '" & txtReleased & "', Department = '" & cboDepartment & "', Status = '" & cboStatus & "' WHERE IDNumber = '" & txtIDNumber & "';" MsgBox "I.D. successfully Updated.", vbInformation, "Update Success" Call ClearAll Unload Me Call RefreshListview Exit Sub: errorupdate: MsgBox Error.Description, vbExclamation, "Error" Set FindCon = Nothing Set FindRs = Nothing End End Sub
Whole Codes for Module
Public Code:
Public FindCon As ADODB.Connection Public FindRs As ADODB.Recordset Public Sub openCon() Set FindCon = New ADODB.Connection FindCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & App.Path & "\Personnel.mdb;" FindCon.Open End Sub
Public Sub executeQuery(ByVal sql As String) Code:
Public Sub executeQuery(ByVal sql As String) On Error GoTo errorcon Set FindCon = New ADODB.Connection If FindCon.State = adStateOpen Then FindCon.Close End If openCon FindCon.Execute sql, adOpenDynamic, adCmdText Exit Sub: errorcon: MsgBox Error.Description, vbCritical, "Error" Set FindCon = Nothing End End Sub
Public Sub FindRecordset(ByVal query As String) Code:
Public Sub FindRecordset(ByVal query As String) On Error GoTo errorrs Set FindRs = New ADODB.Recordset If FindRs.State = adStateOpen Then FindRs.Close End If openCon FindRs.Open query, FindCon, adOpenDynamic, adLockOptimistic Exit Sub: errorrs: MsgBox Error.Description, vbCritical, "Error" Set FindRs = Nothing End End Sub
Public Sub Public Sub RefreshListview Code:
Public Sub RefreshListview() Dim Itmx As ListItem FindRecordset "Select * From Finder Order By IDNumber" EmployeeMain.Listview.ListItems.Clear While Not FindRs.EOF = True Set Itmx = EmployeeMain.Listview.ListItems.Add(, , FindRs.Fields("Owner")) Itmx.SubItems(1) = FindRs.Fields("IDNumber") Itmx.SubItems(2) = FindRs.Fields("Status") Itmx.SubItems(3) = FindRs.Fields("Department") Itmx.SubItems(4) = FindRs.Fields("Acquired") Itmx.SubItems(5) = FindRs.Fields("Released") FindRs.MoveNext Wend End Sub
Please help me :(
Its part of my Thesis. Thank thank thank thank you soo much!