Code will no recognize a form in the database

C

Cris Biron

The following is a portion of code in a calendar form:

Private Sub Form_Close()
Dim strActiveObjectName As String
On Error GoTo ProcErr

strActiveObjectName = Application.CurrentObjectName & "_Form_Close"

If ctlThisControl.Name = "tckDate" Then
Forms!frmTickets.ctyIconLocNo.SetFocus
End If

If ctlThisControl.Name = "Event Date" Then
Forms![NEWfrmARKEvents Subform].SetFocus
End If

ProcExit:
Exit Sub

ProcErr:
DoCmd.Hourglass False
Application.Echo True
MsgBox "An error has occured in " & strActiveObjectName & ". @@" _
& "Error number " & Err.Number & ": " & Err.Description _
& vbCrLf & vbCrLf & "If this problem persists, note the error
message and " _
& "call your programmer.", , "Ooops . . . (unexpected error)"
Resume ProcExit
End Sub

"ctlThisControl" is the control for the calendar form. They may be
"tckDate" or "Event Date" on the forms "frmTickets" and "NEWfrmARKEvents
Subform" respectively.

The first IF .. THEN... block works well, that's it, when the calendar is
open from the first form/control, however, the second does not.

I get the following error:

"Error number 2450: Microsoft can't find the form " NEWfrmARKEvents Subform"
referred to in ... visual Basic code"

Anybody knows why this is happening or what is the solution?

Thanks,

cris biron
 
R

Roger Carlson

If NEWfrmARKEvents Subform is a subform of frmTickets, then you need to
reference it like this:
Forms!frmTickets![NEWfrmARKEvents Subform].Form.SetFocus

On my website (www.rogersaccesslibrary.com), there is a small Access
database sample called SubformReference.mdb which illustrates how to
reference a number of things with forms, subforms, and sub-subforms.

--
--Roger Carlson
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
C

Cris Biron

Thanks Roger. Very helpful

Cris

Roger Carlson said:
If NEWfrmARKEvents Subform is a subform of frmTickets, then you need to
reference it like this:
Forms!frmTickets![NEWfrmARKEvents Subform].Form.SetFocus

On my website (www.rogersaccesslibrary.com), there is a small Access
database sample called SubformReference.mdb which illustrates how to
reference a number of things with forms, subforms, and sub-subforms.

--
--Roger Carlson
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L


Cris Biron said:
The following is a portion of code in a calendar form:

Private Sub Form_Close()
Dim strActiveObjectName As String
On Error GoTo ProcErr

strActiveObjectName = Application.CurrentObjectName & "_Form_Close"

If ctlThisControl.Name = "tckDate" Then
Forms!frmTickets.ctyIconLocNo.SetFocus
End If

If ctlThisControl.Name = "Event Date" Then
Forms![NEWfrmARKEvents Subform].SetFocus
End If

ProcExit:
Exit Sub

ProcErr:
DoCmd.Hourglass False
Application.Echo True
MsgBox "An error has occured in " & strActiveObjectName & ". @@" _
& "Error number " & Err.Number & ": " & Err.Description _
& vbCrLf & vbCrLf & "If this problem persists, note the error
message and " _
& "call your programmer.", , "Ooops . . . (unexpected error)"
Resume ProcExit
End Sub

"ctlThisControl" is the control for the calendar form. They may be
"tckDate" or "Event Date" on the forms "frmTickets" and "NEWfrmARKEvents
Subform" respectively.

The first IF .. THEN... block works well, that's it, when the calendar is
open from the first form/control, however, the second does not.

I get the following error:

"Error number 2450: Microsoft can't find the form " NEWfrmARKEvents Subform"
referred to in ... visual Basic code"

Anybody knows why this is happening or what is the solution?

Thanks,

cris biron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top