1

Why am i getting this error? This code is right but why?

Private Sub loadEmployee()
With frmEmployee.lvEmployee.ListItems
Call connect
'SQL = "SELECT * FROM tblemployee "
Rs.Open "SELECT * FROM tblemployee ", Conn, adOpenDynamic, adLockOptimistic
  If Not Rs.EOF Then
    Rs.MoveLast
    Set Item = lvEmployee.ListItems.Add(1, , Rs!id)
        Item.SubItems(2) = Rs!firstname
        'Item.SubItems(2) = Rs!middlename
        Item.SubItems(3) = Rs!lastname
        Item.SubItems(4) = Rs!agename
        Item.SubItems(5) = Rs!gender
        Item.SubItems(6) = Rs!address
        Item.SubItems(7) = Rs!datehired
        Item.SubItems(8) = Rs!birthdate
        Item.SubItems(9) = Rs!birthplace
        Item.SubItems(10) = Rs!citizenship
        Item.SubItems(11) = Rs!cellno
        Item.SubItems(12) = Rs!Status
        Item.SubItems(13) = Rs!basicsalary
        Item.SubItems(14) = Rs!designation
        Item.SubItems(15) = Rs!department
        'Item.SubItems(16) = Rs!m_name
        'Item.SubItems(17) = Rs!m_occupation
        'Item.SubItems(18) = Rs!n_spouse
        'Item.SubItems(19) = Rs!dependents
        'Item.SubItems(20) = Rs!SSS
        'Item.SubItems(21) = Rs!PHILHEALTH
        'Item.SubItems(22) = Rs!PAGIBIG
        Item.EnsureVisible
  End If
  Rs.Close
  Conn.Close
  Set Conn = Nothing
 End With
End Sub

ERROR:

Arguments not optional

Really having hard time with this. This error is when calling.I called like this:

Private Sub Form_Load()
loadEmployee
End Sub

How to fix this?

Handy Manny
  • 388
  • 1
  • 4
  • 20

2 Answers2

3

Did you declare the Item?

Try declaring:

Dim Item as listitems
scarface23
  • 282
  • 5
  • 15
  • 3
    @HandyMannyand ALWAYS use `Option Explicit`! It would have flagged this error up immediately. – Deanna Apr 09 '13 at 08:46
0

it lacks to declare a value, example I created a method with 12 values ​​I have to reference the same values ​​in the method call.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 07 '23 at 13:27