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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nomatch to findfirst losing recordset

Status
Not open for further replies.

Navel12

Programmer
Feb 21, 2003
17
US
I have been racking my brain on this one for days now. I have searched the posting but still can not find a solution.

I am using VB6 with Access 2000 to do a lookup to a DAO recordset using Findfirst. As long as the record exists everything works great. If the record is not in the recordset then the recordset goes empty and when I try and Addnew it give me "cancelled by associated object" error message. I have tried checking BOF and EOF but to no avail.

Here is the code....any help would be greatly appreciated!!

Check_ID:
searchstr = "ID = " & Val(add_stud_id)
stdDisp.student.Recordset.FindFirst searchstr
If stdDisp.student.Recordset.NoMatch Then
'If no student record then look up in cross reference file
searchstr = "student_id = " & Val(add_stud_id)
stdDisp.id_crs_tbl.Recordset.FindFirst searchstr
If stdDisp.id_crs_tbl.Recordset.NoMatch Then
If chk_cross.Value = 1 Then
'If no cross reference then create cross reference
'If creating a cross reference then get ID number
new_id = ""
valid_id = False
new_id = InputBox("Enter ID: ", "New ID")
'Make sure new ID does not already exist
GoTo Check_ID


At this point it would loop back to verify that ID does not already exists. If nomatch then it goes on to do an Addnew and gets and error.
 
It's not apparent what happens if it does find "add_stud_id" but I do notice that when you do this
Code:
new_id = InputBox("Enter ID: ", "New ID")
'Make sure new ID does not already exist
GoTo Check_ID
you end up back here
Code:
Check_ID:
searchstr = "ID = " & Val(add_stud_id)
and you are not testing if "new_id" exists. You are retesting if "add_stud_id" exists which, of course, it doesn't because it's unchanged from the first time through the code.

This is an example of why GoTo is discouraged an any context other than [blue]On Error GoTo ...[/blue] where it's the only option.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top