Pls help how to add record,

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alem
    New Member
    • Dec 2006
    • 38

    Pls help how to add record,

    Alem
    Hallo all!

    pls help me how to add record I tried the folwing code but Icould't Add.
    [CODE=vb]
    Private Sub cmdadd_Click()
    Dim S
    On Error GoTo cmdokError
    If cuurentcommand = "Add" Then
    rs.AddNew
    For i = 0 To 15
    rs.Fields(i) = txtx(i)
    Next i
    S = MsgBox("Added", vbOKOnly, "Add")
    rs.Update
    End If
    cmdokEnd:
    cmdokError:
    rs.CancelUpdate

    End Sub
    [/CODE]
    Thank you in advance.
    Last edited by Killer42; Feb 12 '08, 09:50 PM. Reason: Indented the code
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    What is the problem with your code ?

    Is that throwing any error ?

    Comment

    • devonknows
      New Member
      • Nov 2006
      • 137

      #3
      Personally for a start, you are better taking out your
      ' On Error Goto cmdokError '

      This is stopping you receiving your Debug messages as it is
      just canceling the update, so you dont know where the error
      is being triggered

      Have you opened the Connection via RS.Open?
      [CODE=vb]

      Dim conn as New ADODB.Connectio n
      Dim rs as New ADODB.Recordset

      conn.Connection String = "your_connectio n_string_here"
      conn.Open 'Open the connection

      rs.Open "select * from MY_TABLE", conn, adOpenDynamic, adLockOptimisti c

      'you also need to Dim i
      Dim i as Integer

      'Ubound Gives the upper bound of txtx()
      'stops you going subscript out of range in case the bound of txtx changes
      For i = 0 to UBound(txtx)
      RS.Fields(i) = txtx(i)
      next i
      'Update and close your recordset
      rs.Update
      rs.Close
      conn.Close

      [/CODE]

      But before you make any changes, take out the Error handling, and see what error message it gives you back and click Debug on the error it will highlight the line.

      Kind Regards
      Devon

      Comment

      • alem
        New Member
        • Dec 2006
        • 38

        #4
        I thank you all

        but I could'nt go further bu I thank you agin.

        Comment

        Working...