PC Review


Reply
Thread Tools Rate Thread

2003 - MS Calendar Control VBA weirdness

 
 
musclpete
Guest
Posts: n/a
 
      7th May 2009
I have a VBA form that I added 2 text boxes to determine a date range. In
those boxes, it calls a calendar control that's initially invisible. Here's
the code:

Dim sWhere As String
Private Sub tbFrom_MouseDown(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
cal1.Visible = True
sWhere = "From"
End Sub

Private Sub tbThru_MouseDown(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
cal1.Visible = True
sWhere = "Thru"
End Sub

Private Sub cal1_Click()
If sWhere = "From" Then
tbFrom.Text = cal1.Value
Else
tbThru.Text = cal1.Value
End If
sWhere = ""
cal1.Visible = False
End Sub

What's not happening is when I 'mouse down' over either of the text boxes,
the calendar doesn't come up. If I click in the area where the calendar
control is located, then it selects a date even though I can't see what date
I'm selecting. From then it works as expected.
What am I missing? I've tried to put the same code in "dbl-click" and
"change" and still get the same result.
 
Reply With Quote
 
 
 
 
Gary Brown
Guest
Posts: n/a
 
      7th May 2009
1) Create a separate form called 'UFCalendar'

2) Put the active X calendar control on it.

3) Name the calendar control 'AXCalendar'

4) put the following code in the UFCalendar form
- double-clicking will cause date to be stored
'/==========================================/
Private Sub UserForm_Activate()
AXCalendar.Value = Now()
End Sub
'/==========================================/
Private Sub AXCalendar_DblClick()
'put selected date into registry
SaveSetting AppName:="ActiveXCalendar", _
section:="Date", Key:="Value", _
setting:=AXCalendar.Value
Unload UFCalendar
End Sub
'/==========================================/

5) the 2 'MouseDown' subs s/b:
'/==========================================/
Private Sub tbFrom_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, _
ByVal Y As Single)
'show calendar
UFCalendar.Show
'get date from registry and put in textbox
Me.tbFrom.Value = GetSetting(AppName:="ActiveXCalendar", _
section:="Date", Key:="Value")
End Sub
'/==========================================/
'/==========================================/
Private Sub tbThru_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, _
ByVal Y As Single)
'show calendar
UFCalendar.Show
'get date from registry and put in textbox
Me.tbThru.Value = GetSetting(AppName:="ActiveXCalendar", _
section:="Date", Key:="Value")
End Sub
'/==========================================/

--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown



"musclpete" wrote:

> I have a VBA form that I added 2 text boxes to determine a date range. In
> those boxes, it calls a calendar control that's initially invisible. Here's
> the code:
>
> Dim sWhere As String
> Private Sub tbFrom_MouseDown(ByVal Button As Integer, ByVal Shift As
> Integer, ByVal X As Single, ByVal Y As Single)
> cal1.Visible = True
> sWhere = "From"
> End Sub
>
> Private Sub tbThru_MouseDown(ByVal Button As Integer, ByVal Shift As
> Integer, ByVal X As Single, ByVal Y As Single)
> cal1.Visible = True
> sWhere = "Thru"
> End Sub
>
> Private Sub cal1_Click()
> If sWhere = "From" Then
> tbFrom.Text = cal1.Value
> Else
> tbThru.Text = cal1.Value
> End If
> sWhere = ""
> cal1.Visible = False
> End Sub
>
> What's not happening is when I 'mouse down' over either of the text boxes,
> the calendar doesn't come up. If I click in the area where the calendar
> control is located, then it selects a date even though I can't see what date
> I'm selecting. From then it works as expected.
> What am I missing? I've tried to put the same code in "dbl-click" and
> "change" and still get the same result.

 
Reply With Quote
 
musclpete
Guest
Posts: n/a
 
      8th May 2009
So there's no way to create a global var and 'pass' between forms?
Is that why you have to use the registry? Or is it just something funky with
the calendar control?

"Gary Brown" wrote:

> 1) Create a separate form called 'UFCalendar'
>
> 2) Put the active X calendar control on it.
>
> 3) Name the calendar control 'AXCalendar'
>
> 4) put the following code in the UFCalendar form
> - double-clicking will cause date to be stored


 
Reply With Quote
 
Gary Brown
Guest
Posts: n/a
 
      8th May 2009
I THINK that the global variables work between modules but I THINK they get
'lost' when switching bwetween forms and modules. So to be safe, I write the
date to the registry then pull it out when I need it and not worry about
scope.
--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown



"musclpete" wrote:

> So there's no way to create a global var and 'pass' between forms?
> Is that why you have to use the registry? Or is it just something funky with
> the calendar control?
>
> "Gary Brown" wrote:
>
> > 1) Create a separate form called 'UFCalendar'
> >
> > 2) Put the active X calendar control on it.
> >
> > 3) Name the calendar control 'AXCalendar'
> >
> > 4) put the following code in the UFCalendar form
> > - double-clicking will cause date to be stored

>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      8th May 2009
Public variables shouldn't get lost unless you do something in the code (or via
the VBE user interface) to reset them.

Gary Brown wrote:
>
> I THINK that the global variables work between modules but I THINK they get
> 'lost' when switching bwetween forms and modules. So to be safe, I write the
> date to the registry then pull it out when I need it and not worry about
> scope.
> --
> Hope this helps.
> If it does, please click the Yes button.
> Thanks in advance for your feedback.
> Gary Brown
>
> "musclpete" wrote:
>
> > So there's no way to create a global var and 'pass' between forms?
> > Is that why you have to use the registry? Or is it just something funky with
> > the calendar control?
> >
> > "Gary Brown" wrote:
> >
> > > 1) Create a separate form called 'UFCalendar'
> > >
> > > 2) Put the active X calendar control on it.
> > >
> > > 3) Name the calendar control 'AXCalendar'
> > >
> > > 4) put the following code in the UFCalendar form
> > > - double-clicking will cause date to be stored

> >


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DST calendar weirdness with Outlook 2000 BTuber Microsoft Outlook Calendar 2 12th Mar 2007 12:47 PM
calendar in pst file weirdness =?Utf-8?B?ZGx3?= Microsoft Outlook Discussion 0 20th Jan 2006 05:55 PM
Tab Control weirdness Doo-Dah Man Microsoft Access Forms 0 20th Jul 2004 01:26 AM
Calendar control weirdness - one post behind? D. Shane Fowlkes Microsoft ASP .NET 2 3rd Mar 2004 06:16 PM
Control-N MainMenu shortcut weirdness with ActiveX Browser control Tom W Microsoft C# .NET 0 20th Jan 2004 05:15 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:38 PM.