Select navigation control or set focus ptoblem (1 Viewer)

leanpilar

Registered User.
Local time
Today, 10:40
Joined
Aug 13, 2015
Messages
94
Hi
I have 3 level of navigation control thant I need to select on form load.
one level is 12 button for 12 month and I need to select the current
I managed to SendKeys "{TAB}", True from 1 to Month(date) then SendKeys "{ENTER}"
but if the form is open the code work good
on load, on resize or on current it select the 09 not the 12...

do you know how to navigate to navigation button or why the code fail on open form??
 

Ranman256

Well-known member
Local time
Today, 04:40
Joined
Apr 9, 2015
Messages
4,337
you dont have to code keyboard actions to run the sub, just run the sub.
Just execute the routine by calling the code:

Code:
sub Form_Load
if month(date) = 1 then  btn1_click
end sub
 

leanpilar

Registered User.
Local time
Today, 10:40
Joined
Aug 13, 2015
Messages
94
the code works but sometimes wrong...

Code:
Private Sub Form_Load()
selectmonth
DoCmd.GoToRecord acDataForm, "myform", acLast
DoCmd.Maximize
End Sub

Code:
Sub selectmonth()
Dim mavcontrol2 As NavigationControl
Dim i As Integer, n As Integer
Set mavcontrol2 = Me.mysubform.Form.Controls("NavigationControlmonth")
Me.mysubform.SetFocus
mavcontrol2.SetFocus
i = Month(Date) [COLOR="Red"]+ 3[/COLOR]
For n = 1 To i
SendKeys "{TAB}", True
Next n
SendKeys "{ENTER}"
if you know how to select the NavigationButton without SendKeys will be the best thing you cand do for this code :D
 

ozinm

Human Coffee Siphon
Local time
Today, 09:40
Joined
Jul 10, 2003
Messages
121
Am I right in thinking you want button 4 to have the focus on the form when it opens when the month is April (as an example)?
If so you don't need to do anything with sendkeys.
call your buttons BtnMonth1, BtnMonth2, BtnMonth3 etc.
in your form open sub stick this in:

Code:
me.form.controls("btnMonth" & cstr(Month(Date()) ).setfocus

NB: I'm not near my Windows PC at the moment so I may have mistyped something here but hopefully you'll get the general idea.
 

leanpilar

Registered User.
Local time
Today, 10:40
Joined
Aug 13, 2015
Messages
94
Yes I try this way too. But it get focus but not activate it... reading over the google I found that navigateto or browseto can do that but the best I got is error browse to in not aviable now...
 

ozinm

Human Coffee Siphon
Local time
Today, 09:40
Joined
Jul 10, 2003
Messages
121
When you say "Activate" do you mean run the underlying code?
re-reading your text the buttons are in a subform?
if so, just make the sub code for the button public and call it.
Something like this:
me.MySubFormName.btnMonth_click
 

leanpilar

Registered User.
Local time
Today, 10:40
Joined
Aug 13, 2015
Messages
94
I think that because English is my 2nd foreign language I didn't explain myself enough good so I make a simple DB so you can see the difference.
The test button activate the code and you will see the 4 (april for example)
get focus but not activate the Navigationbutton
if you open the code in module 1 and activate the last line sendKeys "enter" it will activate

I need some code to .....NavigationButton43."activate"
 

Attachments

  • navigationcontrolcommand.accdb
    692 KB · Views: 155

Users who are viewing this thread

Top Bottom