By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,828 Members | 1,140 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,828 IT Pros & Developers. It's quick & easy.

Tricky syntax for subform and subsubform

P: 9
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
May 31 '07 #1
Share this Question
Share on Google+
4 Replies

dima69
Expert 100+
P: 181
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 ?
May 31 '07 #2

P: 9
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.
May 31 '07 #3

P: 9
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.  
May 31 '07 #4

MMcCarthy
Expert Mod 10K+
P: 14,534
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
Jun 1 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.