Connecting Tech Pros Worldwide Forums | Help | Site Map

Tricky syntax for subform and subsubform

Newbie
 
Join Date: May 2007
Posts: 9
#1: May 31 '07
Hi all

I've got a subsubform called newsubCRBSI which sits on the subform called subfrmlines.

Mousedown on newsubCRBSI.CRBSIDate nicely brings up a calendar on subfrmlines as below...

Expand|Select|Wrap|Line Numbers
  1. Private Sub CRBSIDate_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2. Me.Parent!Calendar4.Visible = True
  3. Me.Parent!Calendar4.SetFocus
  4. If Not IsNull(CRBSIDate) Then
  5.     Me.Parent!Calendar4.Value = CRBSIDate.Value
  6. Else
  7.     Me.Parent!Calendar4.Value = Date
  8.  
  9. End If
  10. End Sub 
but when it comes time for the Calendar value to get transferred back down to CRBSIDate it crashes with "Runtime error 2465 …”can’t find the field ‘newsubCRBSI’ referred to in your expression""
Problems are at Line 11 below

The code looks right to me:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Calendar4_Click()
  2. If Calendar4.Value > Date Then
  3. MsgBox "Culture Date cannot be in the future."
  4.             Calendar4.SetFocus
  5.             Calendar4.Value = Date
  6. ElseIf Calendar4.Value < Insertion Then
  7.     Call MsgBox("Culture Date cannot Precede Line Insertion Date", , "NICU Line Infection Database")
  8.             Calendar4.SetFocus
  9.             Calendar4.Value = Insertion
  10.   Else
  11. Me!newsubCRBSI.Form!CRBSIDate.Value = Calendar4.Value
  12.   Me!newsubCRBSI.Form!CRBSIDate.SetFocus
  13. Calendar4.Visible = False
  14. End If
  15. End Sub
Help!

Michael

dima69's Avatar
Expert
 
Join Date: Sep 2006
Location: Israel
Posts: 181
#2: May 31 '07

re: Tricky syntax for subform and subsubform


Quote:

Originally Posted by kiwipedia

Hi all

I've got a subsubform called newsubCRBSI which sits on the subform called subfrmlines.

Mousedown on newsubCRBSI.CRBSIDate nicely brings up a calendar on subfrmlines as below...

Expand|Select|Wrap|Line Numbers
  1. Private Sub CRBSIDate_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2. Me.Parent!Calendar4.Visible = True
  3. Me.Parent!Calendar4.SetFocus
  4. If Not IsNull(CRBSIDate) Then
  5.     Me.Parent!Calendar4.Value = CRBSIDate.Value
  6. Else
  7.     Me.Parent!Calendar4.Value = Date
  8.  
  9. End If
  10. End Sub 
but when it comes time for the Calendar value to get transferred back down to CRBSIDate it crashes with "Runtime error 2465 …”can’t find the field ‘newsubCRBSI’ referred to in your expression""
Problems are at Line 11 below

The code looks right to me:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Calendar4_Click()
  2. If Calendar4.Value > Date Then
  3. MsgBox "Culture Date cannot be in the future."
  4.             Calendar4.SetFocus
  5.             Calendar4.Value = Date
  6. ElseIf Calendar4.Value < Insertion Then
  7.     Call MsgBox("Culture Date cannot Precede Line Insertion Date", , "NICU Line Infection Database")
  8.             Calendar4.SetFocus
  9.             Calendar4.Value = Insertion
  10.   Else
  11. Me!newsubCRBSI.Form!CRBSIDate.Value = Calendar4.Value
  12.   Me!newsubCRBSI.Form!CRBSIDate.SetFocus
  13. Calendar4.Visible = False
  14. End If
  15. End Sub
Help!

Michael

Are you sure that "newsubCRBSI" is the name of the subform control on the "subfrmlines" form ?
Newbie
 
Join Date: May 2007
Posts: 9
#3: May 31 '07

re: Tricky syntax for subform and subsubform


Quote:

Originally Posted by dima69

Are you sure that "newsubCRBSI" is the name of the subform control on the "subfrmlines" form ?

Thanks dima69
I'm not sure when or why but I had named the subform control CRBSI - hadn't appreciated that the control name and the subform name could get out of synch. So problem solved.

Michael.
Newbie
 
Join Date: May 2007
Posts: 9
#4: Jun 1 '07

re: Tricky syntax for subform and subsubform


Quote:

Originally Posted by kiwipedia

Thanks dima69
I'm not sure when or why but I had named the subform control CRBSI - hadn't appreciated that the control name and the subform name could get out of synch. So problem solved.

Michael.

Out of interest, I then discovered a new problem - that the setfocus didn't work until I first moved focus to the control (located on subfrmlines) of the newsubcrbsi form and only then could I move it to CRBSIDate.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Calendar4_Click()
  2. If Calendar4.Value > Date Then
  3. MsgBox "Culture Date cannot be in the future."
  4.             Calendar4.SetFocus
  5.             Calendar4.Value = Date
  6. ElseIf Calendar4.Value < Insertion Then
  7.     Call MsgBox("Culture Date cannot Precede Line Insertion Date", , "NICU Line Infection Database")
  8.             Calendar4.SetFocus
  9.             Calendar4.Value = Insertion
  10.  
  11. ElseIf Calendar4.Value > (Removal + 2) Then
  12.     Call MsgBox("Culture Date cannot be more than two days after Removal Date", , "NICU Line Infection Database")
  13.             Calendar4.SetFocus
  14.             Calendar4.Value = Removal
  15.  
  16.   Else
  17. Me!CRBSI.SetFocus
  18. Me!CRBSI.Form!CRBSIDate.SetFocus
  19. Me!CRBSI.Form!CRBSIDate.Value = Calendar4.Value
  20.  
  21. Me!Calendar4.Visible = False
  22.  
  23. End If
  24. End Sub
  25.  
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,886
#5: Jun 1 '07

re: Tricky syntax for subform and subsubform


OK, the syntax for referring to subforms is as follows:

If you are on the main form

Expand|Select|Wrap|Line Numbers
  1. Me!Subform1.Form!Subform2.Form!ControlName
or If you are on subform1 then

Expand|Select|Wrap|Line Numbers
  1. Me!Subform2.Form!ControlName
Also you need to check the 'Name' property of the subforms. You can do this by clicking on the subform object frame in design view and open properties. You will find the Name property under the other tab. Never assume that the subform object has the same name as the subforms name.

Mary
Reply