Results 1 to 5 of 5

Thread: RS Problems!Can u Fix?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    RS Problems!Can u Fix?

    ok I have a form where I display data from db.
    I find the record based on the date assigned to it and display on form.
    I want user to be able to update the date of the record from the form. But if I base my sql on the dates how can I update the date field?

    Problem: Can not update a record that doesn't exist!

    Code:
    Case 1 ' updating current record with new data
                Dim strMsg As String, strNewMsg As String
                    Set rs = New Recordset
                    sql = "SELECT * FROM NEM WHERE MMDD = '" & txtEntry(0).Text & "'"
                    rs.Open sql, cnCon, adOpenDynamic, adLockOptimistic
                    If Not rs.EOF Then ' if record found
                        
                            rs.Update
                            rs.Fields!MMDD = txtEntry(0).Text
                            rs.Fields!MonthDay = txtEntry(1).Text
                            rs.Fields!Title = txtEntry(2).Text
                            rs.Update
                            sql = ""
                            rs.Close
                            Set rs = Nothing
                            Text1(0).SetFocus
                        
                    Else
    
                            rs.AddNew
                            rs.Fields!MMDD = txtEntry(0).Text
                            rs.Fields!MonthDay = txtEntry(1).Text
                            rs.Fields!Title = txtEntry(2).Text
                            rs.Update
                            sql = ""
                            rs.Close
                            Set rs = Nothing
                            Text1(0).SetFocus
                    End If
    Last edited by jesus4u; Jun 6th, 2001 at 01:37 PM.

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    it hink your if statement should be

    Code:
    If not rs.eof or rs.bof then
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    Lively Member
    Join Date
    Mar 2001
    Location
    India
    Posts
    97
    if rs.EOF then 'if no record change the sql
    rs.close
    rs.open" select * from NEM"
    rs.AddNew
    rs.Fields!MMDD = txtEntry(0).Text
    rs.Fields!MonthDay = txtEntry(1).Text
    rs.Fields!Title = txtEntry(2).Text
    rs.Update
    sql = ""
    rs.Close
    Set rs = Nothing
    Text1(0).SetFocus
    endif

    hope i make the point ..

    capreal26

  4. #4
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    Instead of using .Update first, use .Edit first and then .Update
    Code:
    RS.Edit
    RS.MMDD='Some Value
    RS.Update
    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    thanks guys I got it

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