Must ... lose ... focus...

Posted on 2007-07-20
Medium Priority
Last Modified: 2012-06-27
Access subform, with a bunch of controls, and a label the size of the whole subform that says 'No records found.'

If Form.Open VBA code determines that there is a record, makes label.visible = false, all other controls.visible = true
If Form.Open VBA code determines that there is no record, makes label.visible = true, all other controls.visible = false

Problem is, one control will always have the focus,  so in my quest to make all other controls.visible = false, one must have the focus, therefore will always be active.

Question:  How do you set a form such that no control control that can have the focus, has the focus?

Question by:Jim Horn
LVL 75

Accepted Solution

DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 2000 total points
ID: 19534124
jHo .... hey ....

A sliver of a text box ... with border, back and fore colors matching what ever area you put in it.  Tab Stop = yes.  So, effectively, this control is .. for all practical purposes ... Invisible.

I use this all the time as a 'Focus Hold' ... when I need to disable controls. zzTxtFocusHold.  I always set focus to this control first ... then disable whatever control(s).  That way, I don't need to worry about that stupid error ... 'You can't set the focus ..."

LVL 75
ID: 19534136
OH ... in the form OnOpen ...

zzTxtFocusHold.SetFocus ...


Expert Comment

ID: 19534452
Create a button that is flat, no border, no text (or at least set forecolour to the same as the form) and no code behind it.  Have the focus on that by default (Tab Stop 0).  Then you will always have a control that can have focus.'
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

LVL 34

Expert Comment

ID: 19536564

If whatever Then
Me.Label2.BackStyle = Transparent
Me.Label2.Caption = ""
Me.Label2.BackStyle = normal
Me.Label2.Caption = "Nope...no records"
End If
LVL 66

Author Comment

by:Jim Horn
ID: 19547207
MX - Worked like a charm.  Thanks.  -JHo
LVL 75
ID: 19548529
wow ... great. cool.

As I mentioned ... I basically never have to worry about disabling a control (command button typically) ... I just set focus to that focus hold control first ...

I named it zztxtFocusHold ... so it sorts at the bottom of the controls list on the tool bar :-)

thanks Jim ...

LVL 34

Expert Comment

ID: 19549728
mine was cooler :o)
LVL 75
ID: 19549846
mine is more versatile and flexible and generic ... and works with tuna also.


Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question