UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Error 2110 while trying to set focus to subform    
 
   
lkelly
post Oct 10 2005, 11:32 AM
Post#1



Posts: 10
Joined: 15-September 05



I have code which checks to see if a calculated value on the main form is NULL. That value represents a total value on a subform. If nothing has been entered on the subform, I want to move focus to the subform and force the user to enter something.
Here's the code I'm using:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(RunningTotal) Then
MsgBox ("No Receipt Items entered!")
Me.PersonReceiptItemsSubform.SetFocus
EndIf
End Sub
After filling out the main form, just clicking on the subform seems to trigger the BeforeUpdate event. However, I get a runtime error 2110 on the SetFocus line.
"Microsoft Access can't move the focus to the control PersonReceiptItemsSubform."
In reading the documentation, it says that to set focus to a control on the subform, you have to first set the focus to the subform itself and then set focus to a control. I'm crashing on the first part.
Any ideas?
Thanks.
Go to the top of the page
 
R. Hicks
post Oct 10 2005, 11:37 AM
Post#2


UA Forum Administrator
Posts: 40,487
Joined: 8-February 00
From: Birmingham, Alabama USA


Looks like you need to Cancel the event if the value is a Null ...
CODE
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(RunningTotal) Then
  MsgBox ("No Receipt Items entered!")
  Cancel = True
  Me.PersonReceiptItemsSubform.SetFocus
End If
End Sub

RDH
Go to the top of the page
 
lkelly
post Oct 10 2005, 12:11 PM
Post#3



Posts: 10
Joined: 15-September 05



If I add in the Cancel = True code (which I had in there in an earlier revision), I now get this error:
untime Error: '2110'
Microsoft Office Access can't move the focus to the control PersonReceiptItemsSubform
Any other ideas? I believe I have the name of the subform correct, as it shows up in the context drop down after "Me."
Go to the top of the page
 
R. Hicks
post Oct 10 2005, 12:16 PM
Post#4


UA Forum Administrator
Posts: 40,487
Joined: 8-February 00
From: Birmingham, Alabama USA


This is usually the error number (2110) received if the control you are setting focus to is disabled .. or is hidden from view.
DH
Go to the top of the page
 
lkelly
post Oct 10 2005, 12:30 PM
Post#5



Posts: 10
Joined: 15-September 05



At the point where I'm testing, the subform in question has no records to display. It just shows the empty Datasheet view with the ability to add a new row. If I remove the SetFocus function call which crashes my form, I'm able to click on the subform and add records. So I would think that it means it is enabled and it's certainly visible on the page.
Go to the top of the page
 
lkelly
post Oct 10 2005, 01:03 PM
Post#6



Posts: 10
Joined: 15-September 05



With the Cancel = True code in there, I don't seem to be able to even get to my subform to enter data. Each time I click on the subform, the Before Update event seems to fire on my main form. I then get stuck with the message box and the Cancel = True. Clear the message box, click on the subform again, and same result.
Is this behavior possible?
1. Enter data on main form.
2. Check calculated field to see if data exists in subform.
3. If calculated field is Null (no data in subform), force the user to enter subform data. Set focus to subform would be a nice bonus here.
Go to the top of the page
 
R. Hicks
post Oct 10 2005, 01:06 PM
Post#7


UA Forum Administrator
Posts: 40,487
Joined: 8-February 00
From: Birmingham, Alabama USA


If the data in the mainform is altered in any way or on a new record .. the Before Update event of the form will trigger ... this is normal.
DH
Go to the top of the page
 
lkelly
post Oct 10 2005, 01:10 PM
Post#8



Posts: 10
Joined: 15-September 05



So there's no real way to force the entry of data in a subform using the logic I've described?

Is there a different event to check if someone tries to go to a new record on the main form or if they try to close the main form?

(Edit: figured out the Form_Unload event for closing it. Now just need to find if there's an event triggered by going to the next record or trying to add a new record.)

Thanks for the help.
Edited by: lkelly on Mon Oct 10 14:18:53 EDT 2005.
Go to the top of the page
 
R. Hicks
post Oct 10 2005, 01:14 PM
Post#9


UA Forum Administrator
Posts: 40,487
Joined: 8-February 00
From: Birmingham, Alabama USA


I would simply display a message from the before update event of the form stating to the user that an entry needs to be made in the subform before they can continue ...
Then let them navigate to the subform themself ...
But you should be able to do this programically ...
RDH
Go to the top of the page
 
lkelly
post Oct 10 2005, 01:21 PM
Post#10



Posts: 10
Joined: 15-September 05



I think it's the case where they close the form or try to go to a new record - I can display a message box telling them they need to add data to the subform, but if I don't do a Cancel = True it will still allow the form to close/change records. If I do a Cancel = True and have it in the Before Update event, I can't ever get focus on the subform.

Ofeel like I'm close, but haven't discovered the right mix of events to trap. It looks like the Current event is triggered when I go to a new or different record, but I don't know if I can cancel that event. And it looks like the Current event is triggered when you open the form, so I can't have cancel code in that case. They need to be able to open the form to begin with...

Argh.

Edited by: lkelly on Mon Oct 10 14:50:32 EDT 2005.
Go to the top of the page
 
R. Hicks
post Oct 10 2005, 01:30 PM
Post#11


UA Forum Administrator
Posts: 40,487
Joined: 8-February 00
From: Birmingham, Alabama USA


You "must" envoke the Cancel = True in the Before Update event of the form ...
DH
Go to the top of the page
 
lkelly
post Oct 10 2005, 01:55 PM
Post#12



Posts: 10
Joined: 15-September 05



But my catch 22: If I insert the Cancel = True code into the Before Update event for the main form, I can't ever get focus on the subform.
Go to the top of the page
 
R. Hicks
post Oct 10 2005, 02:03 PM
Post#13


UA Forum Administrator
Posts: 40,487
Joined: 8-February 00
From: Birmingham, Alabama USA


That makes no sense ...
The Cancel argument only stop the form from committing the data to the table and halts the navigating or closing of the form.
RDH
Go to the top of the page
 
lkelly
post Oct 10 2005, 02:21 PM
Post#14



Posts: 10
Joined: 15-September 05



My results don't seem consistent with that statement.
This simple code (removing the message box):
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(RunningTotal) Then
Cancel = True
End If
End Sub
Doesn't allow me to ever get focus on the subform. I can click on it over and over - nada.
Comment out the Cancel = True, and suddenly I can get focus.
Go to the top of the page
 
hvac
post Oct 10 2005, 02:25 PM
Post#15



Posts: 123
Joined: 16-August 02
From: Arkansas


Try Using
CODE
Me!PersonReceiptItemsSubform.Form.SetFocus

Or
CODE
Forms!MainFormName!PersonReceiptItemsSubform.Form!SetFocus
Go to the top of the page
 
lkelly
post Oct 10 2005, 02:56 PM
Post#16



Posts: 10
Joined: 15-September 05



The latter is giving me a syntax error, the former is giving me a "Runtime Error 2449 - There is an invalid method in an expression."
Yes, I did replace "MainFormName" with the name of the form in the first code suggestion.
Go to the top of the page
 
hvac
post Oct 10 2005, 03:04 PM
Post#17



Posts: 123
Joined: 16-August 02
From: Arkansas


My apologies
CODE
Forms!MainFormName!PersonReceiptItemsSubform.Form!ControlName.SetFocus

Or
CODE
Me!PersonReceiptItemsSubform.Form.ControlName.SetFocus

Print or Bookmark this reference. It's a must Have!!
http://www.mvps.org/access/forms/frm0031.htm
Go to the top of the page
 
lkelly
post Oct 10 2005, 03:51 PM
Post#18



Posts: 10
Joined: 15-September 05



That last syntax seems to pass the test, but unfortunately the Cancel = True statement still keeps me from leaving the focus of the main form. That seems to be the killer - I can try to set focus to the subform before or after the Cancel = True statement, but it just gets killed by the Cancel value.
Go to the top of the page
 
hvac
post Oct 10 2005, 04:34 PM
Post#19



Posts: 123
Joined: 16-August 02
From: Arkansas


Try
[code]Try
[code]Private Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Me.RunningTotal & vbNullString)=0 Then
MsgBox ("No Receipt Items entered!")
Cancel = True
Me.RunningTotal.Setfocus 'Set focus to Main Form First
Me!PersonReceiptItemsSubform.Form.ControlName.SetFocus
End If
End Sub
[code]
You may have to set the focus to the main form before moving to the subform...(Not Tested)
Don't forget to rename the ControlName to your ControlName
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    20th November 2018 - 08:48 PM