Subform control reference prpblem

  • Thread starter Frankie via AccessMonster.com
  • Start date
F

Frankie via AccessMonster.com

I am trying to use the following code on the AfterUpdate Event of a
mainform [F_FicheContrat] which contains one subform
[F_FicheAvenant_sous_formulaire](this is also the subform control name):

If IsNull(Me!F_FicheAvenant_sous_formulaire.Form!DateFinAVT) And Me!DateFin
< Date = False Then
CurrentDb.Execute "UPDATE T_Missions SET " _
& "Contrat = True WHERE IDMission = " _
& Me!IDMission, dbFailOnError
ElseIf IsNull(Me!F_FicheAvenant_sous_formulaire.Form!DateFinAVT) And Me!
DateFin < Date = True Then
CurrentDb.Execute "UPDATE T_Missions SET " _
& "Contrat = False WHERE IDMission = " _
& Me!IDMission, dbFailOnError
ElseIf Not IsNull(Me!F_FicheAvenant_sous_formulaire.Form!DateFinAVT) And Me!
F_FicheAvenant_sous_formulaire.Form!DateFinAVT < Date = False Then
CurrentDb.Execute "UPDATE T_Missions SET " _
& "Contrat = True WHERE IDMission = " _
& Me!IDMission, dbFailOnError
ElseIf Not IsNull(Me!F_FicheAvenant_sous_formulaire.Form!DateFinAVT) And
Me!F_FicheAvenant_sous_formulaire.Form!DateFinAVT < Date = True Then
CurrentDb.Execute "UPDATE T_Missions SET " _
& "Contrat = False WHERE IDMission = " _
& Me!IDMission, dbFailOnError
End If

It keeps returning error #2455.
I just don't understand.
Can someone help me please ??
Thanks in advance
Frankie.
 
A

Allen Browne

Open the main form in design view.
Right-click the edge of the subform control, and choose Properties.
What is the Name of the subform control (Other tab of Properties box)?
It can be different from its SourceObject (the name of the subform that gets
loaded into the control).

If that is not the issue, break the expression down to find out which part
is causing the problem:

If IsNull(Me!F_FicheAvenant_sous_formulaire.Form!DateFinAVT) Then
Debug.Print "Me!F_FicheAvenant_sous_formulaire.Form!DateFinAVT is ok"
End If

If Not IsNull(Me!F_FicheAvenant_sous_formulaire.Form!DateFinAVT) Then
Debug.Print "Me!F_FicheAvenant_sous_formulaire.Form!DateFinAVT is ok"
End If

If Me!DateFin < Date Then
Debug.Print "Me!DateFin is ok"
End If

If Me!DateFin >= Date Then
Debug.Print "Me!DateFin is ok"
End If

If IsNull(Me!DateFin) Then
Debug.Print "Me!DateFin is ok"
End If
 
F

Frankie via AccessMonster.com

Thank you for your response and sorry for coming back so late!
I tried wh
 
F

Frankie via AccessMonster.com

Thank you for your response and sorry for getting back so late!
I tried what you suggest and I realised it worked when there are records on
subform but not when there aren't any.
Is there something I missed in the syntax when refering to subform empty
fields (no records)??
 
A

Allen Browne

Two possible cases here if the subform has no records.

If you are able to add new records in the subform, Access will display the
new record, and the values will be null (assuming no DefaultValue). Treat
these as you would Nulls.

If you cannot add new records in the subform, it goes completely blank when
there are no matching records. In this case, trying to refer to the
non-existent controls in the subform generates an error. Your code will need
to use error-handling to recover, or test the subform's form's
RecordsetClone's RecordCount property.
 
F

Frankie via AccessMonster.com

Allen,

Thank you for your follow-up.
I have been trying different things, looking up at like problem threads (a
lot!) to no avail so far.
My subform allows new record entry. But I even tried the
RecordsetClone.RecordCount which didn't work.
I find myself quite puzzled with this issue!!
Could it be a Dll reference problem??
 

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