OnEnter Event

  • Thread starter Thread starter XMan
  • Start date Start date
X

XMan

I have combo box that I need to put code in OnEnter event. My code is this:

Private Sub cbxSite_Enter()
Dim strSQL As String

strSQL = "SELECT LOCATIONS_WITHIN.LOCATION_WITHIN_UI,
LOCATIONS.DESCRIPTION "
strSQL = strSQL & "FROM LOCATIONS_WITHIN INNER JOIN LOCATIONS ON
LOCATIONS_WITHIN.LOCATION_SUB_UI = LOCATIONS.LOCATION_UI "
strSQL = strSQL & "WHERE LOCATIONS_WITHIN.LOCATION_TOP_UI = " &
Me!cbxSite.Column(0) & " "
strSQL = strSQL & "ORDER BY LOCATIONS.SORT_ORDER, LOCATIONS.DESCRIPTION"

Me.Parent!frmImpactUnit.Form!cbxUnit.RowSource = strSQL

End Sub

When form starts up, this event is triggered and I've got error on this code
saying no object reference there
Me.Parent!frmImpactUnit.Form!cbxUnit.RowSource = strSQL

How can I check for form loading and not run this code? TIA.
 
The problem is Access loads the subform first, and if this is the first
control on the subform, then this code will try to run. The simplest
solution is to put:

On Error Resume Next

... just before the last statement in the procedure that is referencing the
Parent property. You'll get another Enter event after the outer form loads,
and the statement will do what you want.

--
John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
http://www.deanforamerica.com/site/TR?pg=personal&fr_id=1090&px=1434411
 
It appears that you are trying to assign the SQL to the row source of a combo box on
another subform of the parent form, is this correct? If so, is "frmImpactUnit" the name of
the subform or the control on the main form that holds the subform? It should be the
latter.
 
Thanks for your help.

John Viescas said:
The problem is Access loads the subform first, and if this is the first
control on the subform, then this code will try to run. The simplest
solution is to put:

On Error Resume Next

.. just before the last statement in the procedure that is referencing the
Parent property. You'll get another Enter event after the outer form loads,
and the statement will do what you want.

--
John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
http://www.deanforamerica.com/site/TR?pg=personal&fr_id=1090&px=1434411
 
Back
Top