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

Code error for non-executing line inside If...Then !!??

Status
Not open for further replies.

diwin

Technical User
Nov 29, 2002
218
CA
In one subform, the following code is part of the OnCurrent sub and makes another subform update. It works fine all the time, except when the first subform is sorted by hitting 'A-Z' and then I select a record that has subordinate data that would be displayed in the second subform, but not when I select a record that has no subordinate data.

How is it possible to get this error on line in red text...

[tab][blue]Run-time error '2110':
[tab]..can't move the focus to the control subfrmYearList[/blue]

...from this code...

[tab][blue]MsgBox "Just Before: " & DCount[tab]("ID", "qryYearsList")
[tab] If DCount("ID", "qryYearsList") <> 0 Then
[tab] MsgBox "Inside: " & DCount[tab]("ID", "qryYearsList")
[tab] Me.Parent![tab]subfrmYearList.SetFocus
[tab] DoCmd.GoToRecord , , acFirst
[tab] Me.Parent!subfrmSubWatershedList.SetFocus
[tab] End If[/blue]

...when first msgBox shows: 'Just Before: 0', and
second msgBox does not show?

Daniel Dillon
O o . (<--- brain shrinking at rate shown.)
 
Here is a better replication of the code, minus spaces.

[Tab][blue]MsgBox "Just Before: " & DCount("ID", "qryYearsList")
[Tab]If DCount("ID", "qryYearsList") <> 0 Then
[Tab][Tab]MsgBox "Inside: " & DCount("ID", "qryYearsList")
[Tab][Tab]Me.Parent!subfrmYearList.SetFocus
[Tab][Tab]DoCmd.GoToRecord , , acFirst
[Tab][Tab]Me.Parent!subfrmSubWatershedList.SetFocus
[Tab]End If[/blue]

Daniel Dillon
O o . (<--- brain shrinking at rate shown.)
 
I don't have much of an answer, but one question for you: If you hit control+break, or choose "debug", when the error happens, does it take you to that line in the code, or another line?

Are you able to reproduce the error when stepping through in debug mode? I know that maybe you can't, but if you can then that should help answer your question...

Anyways, here's an idea: Instead of using .setfocus followed by docmd.gotorecord, , acFirst to move to the first record, then one possible solution would be to use recordset bookmarks instead. It's been a while (4 or 5 years) since I've done it, but IIRC you can take the recordsetclone's recordset and move it to the first record, then you can get a bookmark from the recordsetclone and set the form's recordset bookmark equal to that bookmark, and IIRC that will accomplish what you are trying to do. If you can't figure this out from my description, or if it doesn't work, then Maybe I could take some time to work up the code. Sincerely,


Jason
 
Thanks Jason.

OK.
This is on hold until I add one more level of complexity to the database. You know, the one that they never thought to tell me about until it is done?---That one.
Everybody is in a rush for this database and they want to migrate from innumerable chaotic spreadsheets, each with different layouts, so they want a database that "just" does this, and "just" does that, and ... "oh--can't you "JUST" add a field to one of the tables for that?"

My mistake--permitting them to rush me.

I will come back to this later if it still exists after the pending overhaul.


Daniel Dillon
O o . (<--- brain shrinking at rate shown.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top