Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"You can't go to the specified record"" error with SQL DAO recor

Status
Not open for further replies.

LexSteel

Programmer
Dec 19, 2001
6
US
Thanks in advance for any help, you'll be a real lifesaver.
Anyway, when I try to update a unbound table based on a bound field in the current record, I get a "
"You can't go to the specified record"" error and the field is not updated. The bound table stores the correct data, but the unbound field fails to update. Anyone have an idea what's wrong?
Thanks...
On Error GoTo form_err

Dim db As Database, rs As DAO.Recordset
Dim meetingdate As Date
Dim x As String

txtID.SetFocus
x = txtID.Text


Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM Contacts WHERE contactID LIKE '" & _
x & "'", dbOpenDynaset)
meetingdate = Me!CallDate
With rs
.MoveFirst
.Edit
.Fields("LastMeetingDate") = meetingdate
.Update
End With
rs.Close
'db.Close
Form_after_update_Exit:
Exit Sub
form_err:
MsgBox Err.Description
Resume Form_after_update_Exit
ContactID.SetFocus
End Sub

Originally, I was getting a "No current record" message, but then after further work, this is what I'm getting.
Thanks!
 
Well first off I'm uncomfortable with you using LIKE when you don't need to. Only use LIKE in combination with wild card characters. Use:-
Set rs = db.OpenRecordset("SELECT * FROM Contacts WHERE contactID = '" & _
x & "';", dbOpenDynaset)

Then lets check how many records return. Add
If rs.EOF Then
Msgbox "No Records returned."
Else
meetingdate = Me!CallDate
rs.MoveLast
If rs.RecordCount = 1 then
rs.Edit
rs!LastMeetingDate = MeetingDate
rs.Update
Else
Msgbox rs.Recordcount & " record(s) were returned."
rs.MoveFirst
rs.Edit
rs!LastMeetingDate = MeetingDate
rs.Update
End If
End If


etc .. ..

Then when you get back the "No Records returned." message you can look to your data with the confidence of knowing that it is not a code problem.


'ope-that-'elps.

G LS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top