|
-
Sep 22nd, 2005, 12:55 PM
#1
Thread Starter
Junior Member
[RESOLVED!] DTPicker and Focus
Hi people
I always use this forum to search for things when i got stuck in some error, but here i have an issue that i cannot find in here
here's the thing:
When i modify, ie, the month part in a dtpicker, and go to another control, if i go back to the dtpicker, the focus is still in the month part, but the dataentrys for the system i am doin', when they go again to the dtpicker, want the focus always be in the day part of it.. i have no clue how to do that, but i think it has to be an easy way to do that
well.. i hope that u can understand my problem since i'm from Argentina and english is not my primary language
thanks,
Ricardo
Last edited by stockton; Sep 23rd, 2005 at 01:39 PM.
Reason: resolved
-
Sep 22nd, 2005, 01:05 PM
#2
Re: DTPicker and Focus
hmm.. Ive tried a number of things and cant get it to do it!??
always wants to be at the month part.. (UNless u click on it)
even tried SendKeys chr$(39) which is the right arrow key
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 22nd, 2005, 01:13 PM
#3
Re: DTPicker and Focus
You can use SendKeys "{LEFT}" (or {RIGHT}) to move the focus to a different date part. Place the code in the GotFocus event.
Unfortunately there is no way to know which date part currently has input focus. You will need to keep track of that manually - unless there is some API functionality that is not implemented in VB but is accessible via SendMessage or something...
-
Sep 22nd, 2005, 01:16 PM
#4
Re: DTPicker and Focus
lol.. i forgot about "{RIGHT}" when testing sendkeys
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 22nd, 2005, 01:22 PM
#5
Re: DTPicker and Focus
Try this
VB Code:
Private testdate As String
Private Sub DTPickter1_Click()
testdate = DTPickter1.Value
End Sub
Private Sub dtpAppealLtrDT_GotFocus()
'need this On Error because the first time it is clicked during
'a session the variable will be empty, and therefore, will generate
'an error
On Error Resume Next
DTPickter1.Value = testdate
End Sub
-
Sep 22nd, 2005, 01:44 PM
#6
Thread Starter
Junior Member
Re: DTPicker and Focus
thanks for the replies..
i will try how to use SendKeys "{LEFT}", but i think it will be kind of hard to code something that works
in the other hand, i don't understand the code by Hack, if u can explain me a little how that work it will be excelent
-
Sep 22nd, 2005, 01:46 PM
#7
Re: DTPicker and Focus
When you pick a date, it stores that date in a variable.
The next time you open the datepickter, it takes what is in that variable for a date and makes it the default date of the datepickter which I believe is what you wanted.
-
Sep 22nd, 2005, 01:59 PM
#8
Thread Starter
Junior Member
Re: DTPicker and Focus
 Originally Posted by Hack
When you pick a date, it stores that date in a variable.
The next time you open the datepickter, it takes what is in that variable for a date and makes it the default date of the datepickter which I believe is what you wanted.
nop, the thing i want is: when the dtpicker got the focus, always the focus be on the day part... that's why, in example, if you change the year part, go to another control, and go back to the dtpicker, the focus will be in the year part of the dtpicker (the last part you changed) instead of being in the day part
-
Sep 23rd, 2005, 01:10 PM
#9
Re: DTPicker and Focus
Sometimes we try to make things too complicated. After thinking about the problem some more I came up with a simple solution.
VB Code:
Private Sub DTPicker1_GotFocus()
'this code moves the focus to the Day input section
'when the date picker control gets focus
'Assumes the date picker is in mm/dd/yyyy format
Dim dteTemp As Date
With DTPicker1
'store the current value because it will be modified.
dteTemp = .Value
'Force a change to the current date section
SendKeys "{UP}", True
If Year(dteTemp) <> .Year Then
'the UP key affected the Year section, so move Left to the Day section.
SendKeys "{LEFT}"
ElseIf Month(dteTemp) <> .Month Then
'the UP key affected the Month section, so move Right to the Day section.
SendKeys "{RIGHT}"
End If
'restore the current value.
.Value = dteTemp
End With
End Sub
The only problem is that this code causes the Change and several KeyDown events to occur, so you may need to "know" when this code is executing. Set the mblnDTPGotFocus variable to True at the beginning of the GotFocus event and back to False at the end.
VB Code:
'form level variable
Private mblnDTPGotFocus As Boolean
Private Sub DTPicker1_Change()
If Not mblnDTPGotFocus Then
'the event is firing because of a user change, not the GotFocus event.
Debug.Print "DTPicker1_Change"
End If
End Sub
-
Sep 23rd, 2005, 01:35 PM
#10
Thread Starter
Junior Member
Re: DTPicker and Focus
Great Bruce !! it worked nice ! very clean and understandable
thank you very much !
-
Sep 23rd, 2005, 11:22 PM
#11
Lively Member
Re: [RESOLVED!] DTPicker and Focus
Thanks Bruce,
I also was trying to resolve the same prob., but can't and last with left it as it is.
now I know this will solve my prob.
Sanjay
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|