473,763 Members | 9,275 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

65 New Member
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.SetFoc us" 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 5119
JKing
1,206 Recognized Expert Top Contributor
Have you tried setting focus to the form itself?
Aug 27 '07 #2
FishVal
2,653 Recognized Expert Specialist
Take a look at this thread
Another SetFocus Question - SetFocus from SubForm
Aug 27 '07 #3
freeskier
65 New Member
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 Recognized Expert Specialist
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 Recognized Expert Expert
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.SetFoc us" 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
freeskier
65 New Member
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 Recognized Expert Expert
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
TerryNah
1 New Member
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.RunComma nd acCmdSelectReco rd) 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.activeco ntrol 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.Previous Conntrol 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
3951
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 appropriate alt text, anyone viewing the page with images turned off, will see the alt text instead, and on hover will see the popups.
6
6118
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 runtime). Does it indicate a problem with References for example? Thanks Owen PS. replies cc'd by email appreciated. owen.southwood@mantix.com
1
2899
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( , formatnumber( , or any other function? Thanks
8
2474
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
2116
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 message, some entry in registry where a log is created (or that enables a log, trace, dump or whatever)... I'm a little bit frustated with this error :-( Tks, Ravi.
0
1924
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 dropdownlist. When i selected a new item in the A dropdownlist, i have this error message : Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control" when i disable EnableStateView for the formview,...
1
2127
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 the menu. Is there a way for this focus click to be ignored and the menu to respond immediately to the first click?
1
2047
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
1986
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 "text box" (named control-A) on "Page-3" Within VBA ... How do I access access "Control-A" on "Page-3". If I have focus set to "Page-1" ?
0
9387
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10148
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10002
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9823
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6643
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.