473,418 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Where should I SetFocus to resolve "can't disable a control when it has the focus"

I have been using the following code to cycle through a subform and disable all textboxes on a form. If a textbox on the form has the focus when this is run I get error "can't disable a control when it has the focus." When I add a line like "txtTest.SetFocus" where txtTest is a textbox on the main form I still get the same error. How do I resolve this issue? Also, please note that I disable all controls on the subform.

Expand|Select|Wrap|Line Numbers
  1. Private Sub EnableControls(ByRef frm As Form, ByRef CtrlTypeName As String, Enable As Boolean)
  2.   Dim nCount As Integer
  3.   For nCount = 0 To frm.Controls.Count - 1
  4.     If TypeName(frm.Controls(nCount)) = CtrlTypeName Then
  5.       frm.Controls(nCount).Enabled = Enable
  6.     End If
  7.   Next
  8. End Sub
  9.  
thank you for your time
Aug 27 '07 #1
8 5069
JKing
1,206 Expert 1GB
Have you tried setting focus to the form itself?
Aug 27 '07 #2
FishVal
2,653 Expert 2GB
Take a look at this thread
Another SetFocus Question - SetFocus from SubForm
Aug 27 '07 #3
Take a look at this thread
Another SetFocus Question - SetFocus from SubForm
is that really the best workaround? to create an empty option group and set borderstyle = transparent?
Aug 30 '07 #4
FishVal
2,653 Expert 2GB
is that really the best workaround? to create an empty option group and set borderstyle = transparent?
Another workaround may be to select current record before disabling last control
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunCommand acCmdSelectRecord 
  2.  
Aug 30 '07 #5
ADezii
8,834 Expert 8TB
I have been using the following code to cycle through a subform and disable all textboxes on a form. If a textbox on the form has the focus when this is run I get error "can't disable a control when it has the focus." When I add a line like "txtTest.SetFocus" where txtTest is a textbox on the main form I still get the same error. How do I resolve this issue? Also, please note that I disable all controls on the subform.

Expand|Select|Wrap|Line Numbers
  1. Private Sub EnableControls(ByRef frm As Form, ByRef CtrlTypeName As String, Enable As Boolean)
  2.   Dim nCount As Integer
  3.   For nCount = 0 To frm.Controls.Count - 1
  4.     If TypeName(frm.Controls(nCount)) = CtrlTypeName Then
  5.       frm.Controls(nCount).Enabled = Enable
  6.     End If
  7.   Next
  8. End Sub
  9.  
thank you for your time
If you're disabling all Text Boxes on a Sub-Form, simply disable the Sub-Form Control itself as in:
Expand|Select|Wrap|Line Numbers
  1. Me!subfChild.Enabled = False
Aug 31 '07 #6
If you're disabling all Text Boxes on a Sub-Form, simply disable the Sub-Form Control itself as in:
Expand|Select|Wrap|Line Numbers
  1. Me!subfChild.Enabled = False
this method doesn't shade disabled objects gray. i got a lot of feedback like "why can't i click on the text box"
Sep 10 '07 #7
ADezii
8,834 Expert 8TB
this method doesn't shade disabled objects gray. i got a lot of feedback like "why can't i click on the text box"
You could 'mimic' the effect:
Expand|Select|Wrap|Line Numbers
  1. Dim ctl As Control
  2. Const conNormal = 1
  3.  
  4. Me!subfChild.Enabled = False
  5.  
  6. For Each ctl In Me!subfChild.Form.Controls
  7.   If ctl.ControlType = acTextBox Then
  8.     ctl.BackStyle = conNormal
  9.     ctl.BackColor = 12632256
  10.   End If
  11. Next
Sep 10 '07 #8
Many thanks! and amazed that this riddle is over. I was looking for a solution that solves a hypothetical prob, where a form consists of 1 text control and a label and when the Label is pressed, the text control is disabled.

After all, if MS access is workable, it's going to have to stand up with these basic features. The solution you provided (DoCmd.RunCommand acCmdSelectRecord) even with a form that doesn't consist a dataset, works.

I was trying to achieve similar results via setting attempting to set the screen.activecontrol to the form object itself. Of course it didn't set the focus to the Form like I was hoping it would; And I was hoping not to have to settle for anything less, like setting focus to arbitrary controls, or as one suggested Screen.PreviousConntrol via PreviousControl.SetFocus because a) makes the code unnecessarily messy and b) you'll need to have at least one other control that the focus can be set to, which doesn't cater for the above prob.
@FishVal
Oct 26 '14 #9

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

Similar topics

4
by: Els | last post by:
Hi, I would like an opinion on the following: I have a page which is made up of background-images with transparent linked images in front of it, which on hover show text in CSS popups. Due to...
6
by: owen | last post by:
Generally speaking, what does it mean when I see a "button" with red text showing this message instead of the control I've dragged onto the web form in Design View.? (But the page works fine at...
1
by: galsaba | last post by:
1. I want to have the value 01 if the number is 1 waht would be the function? 2. i think i need to use the function formatnumber. Where can I find on the web the syntex of cstr( ,...
8
by: Ken Yu | last post by:
Hi, How can i disable "RightClick Menu" in Internet Explorer, when access the frontpage ? tks a lot ! Ken
8
by: Ravi Ambros Wallau | last post by:
Hey guys: What can I do when an "Error Creating Control" is displayed on the form (instead of the control), and a tooltip indicating the error never is displayed? Is there some log, some hidden...
0
by: moi | last post by:
Hello, With ASP.NET 2 , i have two dropdownlist, one "A" (not in a formview) in the web page and other one "B" in a Insert Template in a formview. There's a link (parameter between this two...
1
by: Robert Jones | last post by:
If my application doesn't have focus and someone clicks on the menu, the menu click is "lost" as the form gets focus, and the user then has to click on the menu a second time to actually activate...
1
by: bhushan097 | last post by:
hi , if you control user to right clik on page then why not is is possible to disable "save as" in file menu ? plz suggest solution Bhushan.
3
by: smith1966 | last post by:
Please Help ... I need to reference a particular control that exists on a "tabbed" page eg TABCtl5 has 3 "pages" I have focus set to "TABClt5(Page-1)". I need to access the content of a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.