GoToControl not working sometimes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a button on a form (Access 2002). When clicked, the logic opens a
second form upon which is a tab control. It does a find on a record, and
once found, goes to the Subform that is on the second page of the tab
control. I use the master/child link to determine which records should be
displayed for the sub form.

I load strPageName with the name of that second tab page, I load
sglMYRecordID with an identifier for the record I want to find, then I use
the following:

Open the form.....
DoCmd.GoToControl "My Record ID"
DoCmd.FindRecord sglMYRecordID , acEntire, False, acSearchAll, False,
acCurrent
If strPageName = "My Second Tab" Then
DoCmd.GoToControl "SubFrm_My_Subform"
End If

This all works as long as there is at least one record returned in the
record source for SubFrm_My_Subform.

BUT if there are no records to be returned in the record source for
SubFrm_My_Subform, I get the ubiquitous "Access has encountered a problem and
I must exit....sorry!" message.

What am I doing wrong? How can I fix?
 
Bill said:
I have a button on a form (Access 2002). When clicked, the logic opens a
second form upon which is a tab control. It does a find on a record, and
once found, goes to the Subform that is on the second page of the tab
control. I use the master/child link to determine which records should be
displayed for the sub form.

I load strPageName with the name of that second tab page, I load
sglMYRecordID with an identifier for the record I want to find, then I use
the following:

Open the form.....
DoCmd.GoToControl "My Record ID"
DoCmd.FindRecord sglMYRecordID , acEntire, False, acSearchAll, False,
acCurrent
If strPageName = "My Second Tab" Then
DoCmd.GoToControl "SubFrm_My_Subform"
End If

This all works as long as there is at least one record returned in the
record source for SubFrm_My_Subform.

BUT if there are no records to be returned in the record source for
SubFrm_My_Subform, I get the ubiquitous "Access has encountered a problem and
I must exit....sorry!" message.

What am I doing wrong? How can I fix?


I don't know what might be going wrong. IMO, you should
never get an error that does that.

However, you could check the form recordset's RecordCount
property and avoid the issue:

If Me.RecordsetClone.RecordCount > 0 Then
'your existing code
End If
 
Back
Top