CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Guest

    ADODC and Adding/Deleting/Searching

    Hi,
    I've just started looking into using ADODC, and tried creating an application of very few lines just to get the concepts of adding, deleting, and searching for records in VB6 using ADODC against an MS Access 97 DB.

    However, I'm a bit lost:
    - when I add a record, I can not delete it before I have actually exited and
    restarted the application (moving to another record and back doesn't help)
    - When trying to search, the FindFirst method is not available

    All code I use:
    --00--
    Private Sub CmdAdd_Click()
    Adodc1.Recordset.AddNew
    Me.TxtName.SetFocus
    End Sub
    --
    Private Sub CmdDelete_Click()
    With Adodc1.Recordset
    .Delete
    .MoveFirst
    End With
    End Sub
    --
    Private Sub CmdFind_Click()
    Dim Dummy As String
    Dummy = "*" & FrmDatabase.TxtSearch.Text & "*"
    Adodc1.Recordset.Find "Name Like '" & Dummy & "'"
    End Sub
    --00--

    Basically I think I need a way to update the DB when adding a record, so that I can delete it without restarting the app. Also, I'm following an MSCD book, and the FindFirst method is used for searching. Why is it not available to me? Last question, I'm trying to use "if not .EOF then..." -> However, when I click to navigate to the last record, I am not at EOF until I go to the next record which is blank. Why?

    Any help appreciated ) /Kim ([email protected])


  2. #2
    Join Date
    Feb 2000
    Location
    South Carolina, US
    Posts
    36

    Re: ADODC and Adding/Deleting/Searching

    Among other things, following a call to .AddNew or .Modify, you must call .Update
    ie
    Private Sub CmdAdd_Click()
    Adodc1.Recordset.AddNew
    'line that puts in the data
    Adodc1.Recordset.Update

    as far as .EOF
    While Not RS.EOF
    counter = counter + 1
    theData(counter) = RS!Name
    RS.MoveNext
    Wend
    generally works
    And you'll need more than a .setFocus to actually add data to a record, try something like:
    RS("Name") = "Peter"
    or
    RS!Name = "Peter"
    or even
    RS(1) = "Peter"
    Make sure Name exists and is text 1st.


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

Featured