controliing invisible fields on a form

R

Rajtomar

I have a form with some fields invisible (these fields are kept to
pass values when required for arithmatic calculations) I am looking
for a code which will scan my keyboard strokes and when i press a key
combinations (custom 3 or 4 keys) that time the invisble field should
become visible and as soon as i leave the keys the field should again
get invisible.

thanks
 
T

Tom Wickerath

Hi Rajtomar,

Here is an outline of an approach that I think will work for you, as long as
you can live with pressing 2 keys to toggle the visible state. For example,
you might use:

<Ctrl><V> for make visible (The control and V keys, pressed at the same time)
and
<Ctrl><I> for make hidden (The control and I keys, pressed at the same time,
to make Invisible, or use H for hidden).

You can do this by creating a special macro with the name of Autokeys. This
macro will run when you first open your database, as long as you do not hold
down the Shift key while opening the database. If you must disable startup
functions by holding down the Shift key, then you can always run the Autokeys
macro group by itself, after the database has been opened.

Here is a Microsoft Knowledge Base (KB) article that shows you valid key
combinations in an autokeys macro group:

http://support.microsoft.com/kb/209197

For example:

Macro Name: ^V
Action: RunCode
Function Name: MakeControlsVisible()

and

Macro Name: ^I (or ^H)
Action: RunCode
Function Name: MakeControlsHidden()

You need to create the two functions, MakeControlsVisible() and
MakeControlsHidden() as public functions in a new stand-alone module. If you
are only dealing with one form, the easiest method would be to hard-code the
name of the form into your functions. I *think* (not tested) that you can use
Screen.ActiveForm, if you need this to apply to whatever form is considered
the active form.

The function will need to iterate the controls collection of the form for
control type and perhaps tag property. You could have a tag with each control
that you want to toggle, with some word, such as "Display" (without the
quotes). I'll look up an example of such a function, if you are interested in
pursuing this method.

Another alternative might be to call a macro with the RunMacro action in an
Autokeys macro. Personally, I try to avoid macros like the plague, except for
two special cases: Autoexec and Autokeys.

You might also use the Form's On Key Press event, with Key Preview set to
Yes. I think this would give you the ability to specify more than two keys,
to get you to the 3 or 4 keys that you originally asked about.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top