Refresh boxes

M

Mark S

I have a Switchboard with all unbound controls that I use to build SQL for
the underlying query for another data form. If I enter something into a
textbox and go straight to the button that opens the data form, the value
that I typed into the textbox is not seen. But if I tab off the textbox, it
works fine.

In the On Click for the button that starts the data form I added to the
beginning of the code a Me.Repaint and a SetFocus to another control. That
seems to work OK, but I don't know if that is the best way to do it.

Also, when the data form is called, I just hide the Switchboard (Visible =
false). Then when I close the data form I make the Switchboard visible
again. At that point I also want some of the list and text boxes to return
to their default value.

I have been unable to get these boxes to return to their default value, so I
have been just writing a value back in with code. With the list boxes I have
used Me!Listbox.Selected(0) = True. That will move the list boxes selection
to the first item but it doesn't actually change the value of the list box.

How do you get list boxes and text boxes to actually return the value that
is displayed? How do you get a control to return to its default value?
Would I be better off closing the Switchboard and re-opening it versus using
visible?

Thanks for any help.
 
A

Allen Browne

You're right: Access does not update the Value of a text box until you
complete the entry (typically by leaving the box.)

Think about a text box bound to a date field. You are entering a date like
this:
6/7/
At that moment, the entry is incomplete, so Access could not possibly treat
that text as the Value of the date. If you try to tab out of the control,
you get an error message saying that's not appropriate for the data type.
What happened was that Access attempted to assign the text in the control to
its Value, and that didn't work.

So, you have to tab out of the control before its Value gets updated. You
need to design your interface so the user moves out of the text box before
going on to the next thing. One way to achieve that is to add a command
button for the 'Next' step of the process. By clicking on the button, they
are leaving the text box, and so its Value gets updated.

(It is possible to refer to the text in the control as Text0.Text instead of
just Text0, but I'm not recommending that.)

For your 2nd question, you might be able to use the switchboard's Activate
event so that you reassign values to the controls when it gets focus again.
Here's some code to clear list boxes (whether mulit-select or not):
http://allenbrowne.com/func-12.html

Alternatively, it might be just as easy to close the switchboard and reopen
it.
 

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