Results 1 to 7 of 7

Thread: Access - Calendar Control - popup event

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    52

    Access - Calendar Control - popup event

    I'm trying to use a calendar in Access 2003 to enter data in data fields.
    I found a site that showed how to write the code so it will popup when you click on the date field and then disappear when you select the date from the calendar.
    I got it working but I want to be able to access that same calendar for other date fields on the form.
    So I used a variable call 'originator' to pass the originators name to the variable.
    Only thing is...now it doesn't work. I get a type mismatch error and I don't know why. It's exactly the same as the example I found(obviously with my names substituted in).

    Please help. (dob is the field I want the date to go into and Calendar6 is the name of the calendar I'm using.) Here's my code:


    Option Compare Database
    Option Explicit
    Dim originator As ComboBox

    Private Sub dob_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Set originator = dob
    Calendar6.Visible = True
    Calendar6.SetFocus

    If Not IsNull(originator) Then
    Calendar6.Value = originator.Value
    Else
    Calendar6.Value = Date
    End If

    End Sub

    Private Sub Calendar6_Click()
    originator.Value = Calendar6.Value
    originator.SetFocus
    Calendar6.Visible = False
    Set originator = Nothing

    End Sub

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Access - Calendar Control - popup event

    isn't dob a textbox ---- originator is classed as a combobox?

    shouldn't originator be classed as a control?

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    52

    Re: Access - Calendar Control - popup event

    so you think try putting

    'dim originator as textbox'

    or

    'dim originator as control'

    ?

    I'll try them when I get home from work.

  4. #4
    Lively Member
    Join Date
    Mar 2007
    Posts
    83

    Re: Access - Calendar Control - popup event

    headsbout2burst
    I have a similar feature in one of my access applics. I got it from a website somewhere i dont remember. It uses a module for poping-up the calendar. It works with the on_click event of the textbox or of a little button next to your date txtbox - as you choose to make it in fact.

    It works abs fine. I can upload it all in a small sample db here if ever you cant resolve your current error.
    Good luck

  5. #5
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Access - Calendar Control - popup event

    Code:
    dim originator as control
    Then you can put either textbox of combobox - I assume you are setting the .text property (VB) or the .value property (vba).

    Give it a go and see if it does anything.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    52

    Re: Access - Calendar Control - popup event

    yes, dim originator as control works.

    but now its not inputting the date you select from the calendar, just puts in todays date!! bizzarre...any ideas why?

    here's my revised code:

    Code:
    Option Compare Database
    Option Explicit
    Dim originator As Control
    
    Private Sub dob_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    Set originator = dob
    Calendar6.Visible = True
    Calendar6.SetFocus
    
    If Not IsNull(originator) Then
       Calendar6.Value = originator.Value
    Else
       Calendar6.Value = Date
    End If
    
    End Sub
    
    Private Sub Calendar6_Click()
        originator.Value = Calendar6.Value
        originator.SetFocus
        Calendar6.Visible = False
        Set originator = Nothing
    End Sub

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    52

    Re: Access - Calendar Control - popup event

    I've done it. thanks for your help.
    don't know what was wrong, I just deleted everything and started again. worked this time.

Posting Permissions

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



Click Here to Expand Forum to Full Width