locked
Calendar Pop-Up in Access RRS feed

  • Question

  • I am trying to run a pop-up calendar in Access (I am a SQL girl... not familiar with VB code) and I can't seem to figure out why I keep getting this error:

    Run-time error '91':
    Object variable or With block variable not set

    Can anyone help tell me what is wrong here?  Here is my code:

    Option Compare Database
    Option Explicit
    Dim cboOriginator As ComboBox

    Private Sub cboStartDate_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    ' Note which combo box called the calendar
        Set cboOriginator = cboStartDate
    ' Unhide the calendar and give it the focus
        Calendar6.Visible = True
        Calendar6.SetFocus
    ' Match calendar date to existing date if present or today's date
        If Not IsNull(cboOriginator) Then
            Calendar6.Value = cboOriginator.Value
        Else
            Calendar6.Value = Date
        End If
    End Sub

    Private Sub cboEndDate_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    ' Note which combo box called the calendar
        Set cboOriginator = cboEndDate
    ' Unhide the calendar and give it the focus
        Calendar6.Visible = True
        Calendar6.SetFocus
    ' Match calendar date to existing date if present or today's date
        If Not IsNull(cboOriginator) Then
            Calendar6.Value = cboOriginator.Value
        Else
            Calendar6.Value = Date
        End If
    End Sub

    Private Sub Calendar6_Click()
    ' Copy chosen date from calendar to originating combo box
        cboOriginator.Value = Calendar6.Value
    ' Return the focus to the combo box and hide the calendar and
        cboOriginator.SetFocus
        Calendar6.Visible = False
    ' Empty the variable
        Set cboOriginator.Value = Nothing
    End Sub

    Thanks!  Stacy

    Wednesday, April 19, 2006 5:15 PM

Answers

  • As you are proposing to use Access internal VB which I'm fairly sure is VBA and not VB.Net - these forums are for VB.NET questions.   VBA is a very different product from VB.NET.

    You may find more assistance in following which specifcially deals with MS Office development.

     

    ·         Office Automation: office.developer.automation newsgroup

    http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.office.developer.automation&lang=en&cr=US

     

    Or the  Office Newgroups 

    http://www.microsoft.com/office/community/en-us/default.mspx?d=1

     

    Now to try and give you some answer as to what is being said - and these are trying to think back in the dim distant past to using VBA  in Access

    Try changing the line

    Dim cboOriginator As ComboBox

    to

    Dim cboOriginator As New ComboBox

     

     

    This message generally means that you have set up a reference to a object but not actually set it to anything.

    Putting the new in there will generally create a combobox reference object that points to a new instance of it

     

    Give that a try..

    Wednesday, April 19, 2006 5:24 PM