|
-
Jun 6th, 2001, 01:33 PM
#1
Thread Starter
PowerPoster
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.
-
Jun 6th, 2001, 01:39 PM
#2
it hink your if statement should be
Code:
If not rs.eof or rs.bof then
-
Jun 6th, 2001, 01:41 PM
#3
Lively Member
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
-
Jun 6th, 2001, 01:57 PM
#4
Well ...
Instead of using .Update first, use .Edit first and then .Update
Code:
RS.Edit
RS.MMDD='Some Value
RS.Update
.
-
Jun 6th, 2001, 02:50 PM
#5
Thread Starter
PowerPoster
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|