Consulting

Results 1 to 16 of 16

Thread: Solved: Pop-up calendar confusion

  1. #1
    VBAX Regular
    Joined
    Jan 2007
    Location
    Marietta, GA
    Posts
    9
    Location

    Solved: Pop-up calendar confusion

    Hello all,
    My name is Tim and i'm having some issues with using the pop-up calendar control form in VBA with Excel.

    In the attached workbook i've just used the calendar control 11.0 to generate a pop-up calendar whenever a user clicks in cells a1:a100 on sheet12("January").

    the issues i'm having involve the bit of code attributed to
    private sub userform_initialize() in the userform

    [vba]Private Sub UserForm_Initialize()
    If IsDate(ActiveCell.Value) Then
    Calendar1.Value = DateValue(ActiveCell.Value)
    Else:
    Calendar1.Value = Date
    End If
    End Sub[/vba]

    On the computer i made the userform on initially this code works fine so that when the user clicks on cells a1:a100, if the cell has a date entered the calendar starts on that state, but if the target cell does not have a date already entered, the calendar sets itself to Today's date.

    But...i have another laptop i use to make sure that whatever i'm working on will work on more than one computer and this code doesn't work on it.

    i can't for the life of me figure out why. any thoughts?

    both computers have all available office and windows updates
    both computers have the mscal.ocx file registered and calendar control 11.0 active
    both computers have the same version of and release of VBA
    both have excel 2003

  2. #2
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    I hear you. Actually, that is the primary reason why I abandoned the Calendar Control. Depsite having the same OS, same Office versions, same OCX files registered, I haven't found that you can rely on the Calendar Control at all. I don't profess to be an expert in ActiveX controls, by any means though.

    What I did, though, was change to a 100% VBA based calendar userform built by one of our members. The thread is here. Scroll down to the last post for the final version.

    It would be a bit of work to convert it, for certain, but overall you'll have a much more stable and portable project. (IMO, anyway.)
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  3. #3
    VBAX Regular
    Joined
    Jan 2007
    Location
    Marietta, GA
    Posts
    9
    Location
    Thanks Ken. that seems like it could work really well for me as i had not even begun to think of how to deal with my mac users. I think i'll be able to tweak the trigger event as well as some of the formats to make it a little more basic and thusly perfect for my use. Again, thanks Ken for pointing me in the right direction.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I don't know if this is anything to do with it, but when I opened your workbook I got an error. This was the code as implemented

    [vba]

    Private Sub UserForm_Initialize()
    If IsDate(ActiveCell.Value) Then
    Calendar1.Value = DateValue(ActiveCell.Value)
    Else:
    Calendar1.Value
    End If
    End Sub
    [/vba]

    easily fixed by

    [vba]

    Private Sub UserForm_Initialize()
    If IsDate(ActiveCell.Value) Then
    Calendar1.Value = DateValue(ActiveCell.Value)
    Else:
    Calendar1.Value = Date
    End If
    End Sub
    [/vba]

    It also seems to me that you should turn events off in the change event so that the calendar doesn't pop-up if the date is inserted in column A (manually that is, not via the calendar control).

  5. #5
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by muthill001
    ... this code doesn't work on it...
    Hi Tim,

    Exactly what do you mean by that - what part doesn't work? Your code works fine for me...
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  6. #6
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    You could also try this alternative...
    [VBA]
    Private Sub UserForm_Activate()
    With Calendar1
    If IsDate(ActiveCell) Then
    .Day = Day(ActiveCell)
    .Month = Month(ActiveCell)
    .Year = Year(ActiveCell)
    Else
    .Day = Day(Date)
    .Month = Month(Date)
    .Year = Year(Date)
    End If
    End With
    End Sub
    [/VBA]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  7. #7
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  8. #8
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Steve, I didn't know that was there!

    Nice one!
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  9. #9
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Hi Ken,
    Only reason I remembered is when I went to your link in post 2 of this thread. If you read the earlier entries to the thread......that was a while back but I agree about the portability.....these type of solutions are much better than the native calender control...after you get them set up.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  10. #10
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    LOL!

    Honestly, I remembered that Lief had done several revisions of that code, so I didn't re-read the thread.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  11. #11
    VBAX Regular
    Joined
    Jan 2007
    Location
    Marietta, GA
    Posts
    9
    Location
    "Hi Tim,

    Exactly what do you mean by that - what part doesn't work? Your code works fine for me..."



    yeah...that's exactly the problem i was having. it was working fine (with the addition of the "= Date" in the else expression of the code...i guess i had uploaded the wrong version of the workbook) on the laptop i made the workbook on, but when i opened it up on another, almost identical machine it would throw a "can't find object or library" error. it was driving me crazy. But, there have been some awesome resources made known to me through this thread that i think have taken care of the problem thanks again all.

  12. #12
    VBAX Regular
    Joined
    Jan 2007
    Location
    Marietta, GA
    Posts
    9
    Location

    i'm going crazy

    Alright. So the non activeX based pop-up Calendar from the KB that i was directed to earlier in this thread worked great...for the most part. I'm still having a problem wherein the workbook works great on one computer but not another.

    Here is the code that is throwing the error: in the attached file it is found in the sheet12(January) object

    [vba]Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Intersect(Target, Range("$A$6:$A$100")) Is Nothing Then
    Exit Sub
    Else: Target.Value = getUserDate(Date)
    End If
    End Sub[/vba]

    the error pulls one of those "can't find object or library" and highlights the word "Date" highlighted orange above

    i want a user to be faced with picking a date from the pop-up calendar any time a cell in the range a6:a100 is selected

    I followed the implementation steps for putting the userform and module from the sample file exactly (making user of the transfer button in the file) : vbax_calendar.xls obtained from the KB and while the attached file works perfectly on this computer it does not on the one upstairs.

    Both have excel 2003
    both have VBA 6.3

    what am i missing?

    thanks in advance for any responses.

  13. #13
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    In the VBIDE, go to Tools>References, and see if there are any items with MISSING besides them. If they are, uncheck them.

  14. #14
    VBAX Regular
    Joined
    Jan 2007
    Location
    Marietta, GA
    Posts
    9
    Location
    Quote Originally Posted by xld
    In the VBIDE, go to Tools>References, and see if there are any items with MISSING besides them. If they are, uncheck them.

    AHHH. that is why sleep is good: so you remember to do the most basic, elementary things.

    If we learned anything from the 1985 Marth Coolidge cult classic film Real Genius, it's this: "...Always, no, never....for to check your referencs."

    thanks so much el xld for being smarter than i am.

  15. #15
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Not smarter, just went there before you.

  16. #16
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Quote Originally Posted by xld
    Not smarter, just went there before you.
    No substitute for experience.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •