Results 1 to 12 of 12

Thread: Populating listview on form_load [RESOLVED]

Threaded View

  1. #1

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Resolved Populating listview on form_load [RESOLVED]

    hello! I have searched the forum and found this Thread I tried it on my work but its giving me this "Argument not Optional" error and form_load event is highlighted.

    What i would like to achieved is that on form load, the listview(which has 6 columns) will display the records in my access database.

    When the records are already displayed, the user can single click any row and the same records displayed in that row will also display in 6 textboxes for editing purposes.

    Here's my code:
    VB Code:
    1. Option Explicit
    2. Dim rsStocks As ADODB.Recordset
    3. Dim sSQL$
    4. Private Sub cmdAdd_Click()
    5.   If CheckNullValue = False Then Exit Sub
    6.  
    7.   cmdCancel.Enabled = True
    8.   'lstStocks.Enabled = False
    9.   txtCode.SetFocus
    10.  
    11. On Error GoTo errHandler
    12.  
    13.   With oConn
    14.     .BeginTrans
    15.    
    16.     ' - save to tblStocks -
    17.     '--------------------------------------------------------------
    18.     .Execute "INSERT INTO tblStocks(Code, ProductDescription, UnitPrice, " & _
    19.                   "Quantity, ReOrder)" & _
    20.              "VALUES('" & txtCode.Text & "', '" & txtDesc.Text & "', '" & _
    21.                 txtUnitPrice.Text & "' ,'" & txtQty.Text & "','" & _
    22.                 txtROP.Text & "')", , adCmdText
    23.     '==============================================================
    24.     .CommitTrans
    25.   End With
    26.  
    27.   Call ClearFunction(frmStocks, "TextBox")
    28. Exit Sub
    29. errHandler:
    30.   oConn.RollbackTrans
    31.   Call msgError(Err)
    32. End Sub
    33.  
    34.  
    35. Private Sub cmdCancel_Click()
    36.   Call ClearFunction(frmStocks, "TextBox")
    37.  
    38. End Sub
    39.  
    40. Private Sub cmdClose_Click()
    41.   Unload Me
    42. End Sub
    43.  
    44. Private Sub Form_Load()
    45.   Call openConnection
    46.   Me.Left = LeftPos
    47.   Me.Top = TopPos
    48.  
    49.   Set rsStocks = New ADODB.Recordset
    50.   rsStocks.CursorLocation = adUseClient
    51.  
    52.  
    53.   sSQL = "SELECT * FROM tblStocks"
    54.  
    55.   If rsStocks.State = adStateOpen Then rsStocks.Close
    56.   rsStocks.Open sSQL, oConn, adOpenStatic, adLockOptimistic
    57.   Call FillListView
    58. End Sub
    59.  
    60. Private Sub Form_Unload(Cancel As Integer)
    61.   If rsStocks.State = adStateOpen Then rsStocks.Close
    62.   Set rsStocks = Nothing
    63. End Sub
    64.  
    65. 'TODO : return true if all required field has been filled
    66. Private Function CheckNullValue() As Boolean
    67.   CheckNullValue = False
    68.  
    69.   If Len(Trim$(txtCode.Text)) = 0 Then
    70.     Call msgMustBeFilled("Product Code")
    71.     txtCode.SetFocus
    72.     Exit Function
    73.   ElseIf Len(Trim$(txtDesc.Text)) = 0 Then
    74.     Call msgMustBeFilled("Description")
    75.     txtDesc.SetFocus
    76.     Exit Function
    77.   ElseIf Len(Trim$(txtUnitPrice.Text)) = 0 Then
    78.     Call msgMustBeFilled("Unit Price")
    79.     txtUnitPrice.SetFocus
    80.     Exit Function
    81.   ElseIf Len(Trim$(txtQty.Text)) = 0 Then
    82.     Call msgMustBeFilled("Quantity")
    83.     txtQty.SetFocus
    84.     Exit Function
    85.   ElseIf Len(Trim$(txtROP.Text)) = 0 Then
    86.     Call msgMustBeFilled("Re-Order Point")
    87.     txtROP.SetFocus
    88.     Exit Function
    89.   End If
    90.  
    91.   'If cmdAddCategory.Enabled = True Then Call ReplaceQuotation(txtCategoryName)
    92.   CheckNullValue = True
    93. End Function
    94.  
    95. Sub FillListView(lstStocks As ListView, rsStocks As ADODB.Recordset, Optional ImgNum As Long = 0)
    96.     lstStocks.ListItems.Clear
    97.     If Not rsStocks.BOF Then
    98.         rsStocks.MoveFirst
    99.         Dim a As Long
    100.         Dim lst As ListItem
    101.         While Not rsStocks.EOF
    102.             lst.Ghosted = True
    103.             Set lst = lstStocks.ListItems.Add(, , rsStocks.Fields(0).Value, , ImgNum)
    104.             For a = 1 To lv.ColumnHeaders.Count - 1
    105.                 lst.SubItems(a) = rsStocks.Fields(a).Value
    106.             Next
    107.             rsStocks.MoveNext
    108.         Wend
    109.     End If
    110. End Sub
    Last edited by Hack; Apr 23rd, 2006 at 06:39 AM.
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width