Set focus to label?

B

BethMc

I have a page on a tabbed form consisting of a series of label boxes
(explaining Terms for a rental) with only one control on the page, at the end
(a check box to accept terms). When the page opens, the focus is on the
control. I want the page to open at the top of the Terms series of labels.
Labels don't seem to have a TabIndex property, or any other way to
capture focus. Could I write an OnClick procedure for the page tab, to focus
at the top? Or... what? All assistance gratefully received!
 
L

Linq Adams via AccessMonster.com

You'll need to place an unbound textbox in the upper-most, left-most portion
of the form.

Make a note of the name of the textbox.

Now shrink the textbox until it disappears to the eye.

Go into the form's code window and enter this code

Private Sub Form_Load()
Me.YourTextboxName.SetFocus
End Sub

substituing the actual name of the textbox for YourTextboxName.
 
B

BethMc

I did something wrong...
Created the textbox. Shrank it. Typed name in box: GrabFocus1.
Deleted the label.
Told Access to Ignore the Error for unbound control.
On Property Sheet, named it GrabFocus1.
(NOTE: Created it on Form base, then cut & pasted to desired tab page.)
Went to Module (that's the window I wanted, right?) and typed
Private Sub Form_Load()
Me.GrabFocus1.SetFocus
End Sub [that part appeared on its own]
When I went from Design to Form view, Access crashed and closed - lost the
box completely, also some other recent (minor) changes & additions.
Does it matter that this is on the 2nd tabbed page of the form, not the
beginning of the whole form?

Really appreciate the help!
 
N

NKTower

If you want the text to be in a scrollable window, similar to what you see
when you install a program and have to accept conditions, etc., you could do
it like this...

define an unbound Text box, in my example named myText
Set some properties...
Enabled=True
Locked = True
ScrollBars = Vertical Only
adjust font, color, background, border etc. to suit your needs.

Then, in Form_Open event, put code like this...

' ------------------------------------------------------------------
Private Sub Form_Open(Cancel As Integer)
Dim str_TextSource As String

' put vbCrLF only where you REALLY need a new line.
'I'm doing it just go get a lot of lines.

str_TextSource = "This is a test, " & _
"this is only a test. " & vbCrLf & _
"Had this been a real " & _
"contract or " & vbCrLf & _
"Terms & Conditions, etc." & vbCrLf & _
"we would have" & vbCrLf & _
"spelled them out" & vbCrLf & _
"here with all sorts" & vbCrLf & _
"of mumbo-jumbo" & vbCrLf
' There is a limit of about 17 line continuations, so
' we do it in several steps...

str_TextSource =
str_TextSource & _
"we can go on and one" & vbCrLf & _
"Now is the" & vbCrLf & _
"time for all good" & vbCrLf & _
"men to come to the" & vbCrLf & _
"quick brown fox which " & vbCrLf & _
"is jumping over the lazy " & vbCrLf & _
"dog's back."

Me.myText = str_TextSource
Me.myText.SetFocus
' prevent highlighting the whole thing...
Me.myText.SelStart = 0
Me.myText.SelLength = 0
End Sub
' ------------------------------------------------------------
Of course you could also read the text in from an ASCII file, etc.
(Ask if you don't know how.)

The code above puts the cursor at the start of the text. The scroll bar
will appear. The user may move through the text etc., but can't change it.
 
B

BethMc

I tried it again - no crash this time, but no results either. The page still
opens at the control on the bottom.

Is there a way to tie the Module to the specific Tab page where the box is
located, or otherwise cause it to activate when that tab is selected? I
tried typing the module name into the OnClick box on the Property Sheet - no
change.

Still lost... but thank you for trying!


BethMc said:
I did something wrong...
Created the textbox. Shrank it. Typed name in box: GrabFocus1.
Deleted the label.
Told Access to Ignore the Error for unbound control.
On Property Sheet, named it GrabFocus1.
(NOTE: Created it on Form base, then cut & pasted to desired tab page.)
Went to Module (that's the window I wanted, right?) and typed
Private Sub Form_Load()
Me.GrabFocus1.SetFocus
End Sub [that part appeared on its own]
When I went from Design to Form view, Access crashed and closed - lost the
box completely, also some other recent (minor) changes & additions.
Does it matter that this is on the 2nd tabbed page of the form, not the
beginning of the whole form?

Really appreciate the help!

Linq Adams via AccessMonster.com said:
You'll need to place an unbound textbox in the upper-most, left-most portion
of the form.

Make a note of the name of the textbox.

Now shrink the textbox until it disappears to the eye.

Go into the form's code window and enter this code

Private Sub Form_Load()
Me.YourTextboxName.SetFocus
End Sub

substituing the actual name of the textbox for YourTextboxName.
 
B

BethMc

You have accurately described what I need - but, the necessary text is long -
currently it's in six very full memo boxes. I need to code for every line?
There must be a better way - I hope! - but if that's all I have to work with,
of course I'll have to do it.
Please let me know if there's another way.
 
B

BethMc

Another developement (2, actually) 1. - An error message attached to the Form
properties - "Access was unable to locate the macro or VBA function....If you
are trying to call a user-defined VBA function, be sure to use the following
syntax:
=FunctionName() or =FunctionName(argument1,argument2,...)
Make sure that the function is either:
Defined in the code for the form or report.
- or -
A public function that is in a module (not a class module)."
Does this mean I've entered the code in the wrong place? And, just
where do I put this "=GrabFocus1()"?
ALSO - 2. whenever I try to go to Print Preview, Access asks me to
"Enter Parameter Value" for GrabFocus1. 'True' or 'False' closes the window,
but neither has an effect on performance.
Thanks in advance!
--
Beth McCalley


BethMc said:
I tried it again - no crash this time, but no results either. The page still
opens at the control on the bottom.

Is there a way to tie the Module to the specific Tab page where the box is
located, or otherwise cause it to activate when that tab is selected? I
tried typing the module name into the OnClick box on the Property Sheet - no
change.

Still lost... but thank you for trying!


BethMc said:
I did something wrong...
Created the textbox. Shrank it. Typed name in box: GrabFocus1.
Deleted the label.
Told Access to Ignore the Error for unbound control.
On Property Sheet, named it GrabFocus1.
(NOTE: Created it on Form base, then cut & pasted to desired tab page.)
Went to Module (that's the window I wanted, right?) and typed
Private Sub Form_Load()
Me.GrabFocus1.SetFocus
End Sub [that part appeared on its own]
When I went from Design to Form view, Access crashed and closed - lost the
box completely, also some other recent (minor) changes & additions.
Does it matter that this is on the 2nd tabbed page of the form, not the
beginning of the whole form?

Really appreciate the help!

Linq Adams via AccessMonster.com said:
You'll need to place an unbound textbox in the upper-most, left-most portion
of the form.

Make a note of the name of the textbox.

Now shrink the textbox until it disappears to the eye.

Go into the form's code window and enter this code

Private Sub Form_Load()
Me.YourTextboxName.SetFocus
End Sub

substituing the actual name of the textbox for YourTextboxName.
 
B

BethMc

Thank you, folks, I skinned the cat yet another way... I placed an unbound,
shrunken-to-invisibility textbox at the top of each tab page, then just used
the Tab Order setting (under Arrange on the Design ribbon) to place that new
textbox first on the page. Voila!
Thanks to both of you for your help, I learned alot along the way - such
as, while I can write a macro, as of this point I'd better not mess with
code! :)
 

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