Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is going on?

Status
Not open for further replies.

enak

Programmer
Jul 2, 2002
412
US
I have inherited an Access 2000 db and was asked to upgrade it to 2003. I did the convert to 2000-2003 format and it seems to be working fine.

However, I have a listbox that when it is loaded an OnClick event is added.

ctl.OnClick = "=ShowDaysEvents"

When I click on the listbox I get the following error:

"The expression On Click you entered as the event property setting produced the following error: The object doesn't contain the Automation Object 'ShowDaysEvents'.

Here is the code for the sub:

Public Sub ShowDaysEvents()
'On Error GoTo ErrTrap_ShowDaysEvents
' This procedure is called when the user clicks on one of the command
' buttons on frmCalendar which correspond to dates in the month.
' The selection criteria (filter) are fed to the command button Tag property
' when the calendar is first loaded.

Dim strCriteria As String
Dim strNumber As String
Dim strList As String
Dim ctrl As Control
Dim varItm As Variant

Set ctrl = Screen.ActiveControl


If ctrl.Name Like "cmd*" Then
' This section of code runs when user clicks the command button
' corresponding to the number of the day
strCriteria = ctrl.Tag
' Is there a user-applied filter?
If g_Is_CalFilter Then
strCriteria = ctrl.Tag & " and " & g_CalFilter
End If
g_strDayNum = Mid$(ctrl.Name, 4)
g_strList = Trim("List" & g_strDayNum)
g_DateClicked = ctrl.StatusBarText ' the actual date represented by this command button


' Are there any events listed for the day clicked?
If Me(g_strList).ListCount > 0 Then
g_AddEvent = False
DoCmd.OpenForm "frmCalDayList", , , strCriteria
Else
' There are no events; open a form so that a user WITH RIGHTS
' can add an event. Or, if NO RIGHTS, advise the user that
' there are no events for the date selected.
If g_AllRights Then
g_msg = "There are no events for this date. " _
& "Do you want to add a new event on this date?."
If MsgBox(g_msg, vbYesNo) = vbYes Then
g_AddEvent = True
DoCmd.OpenForm "frmCalDetail", , , , acFormAdd
End If
Me!Text189.SetFocus
Else
MsgBox "There are no records to view for this date."
End If
End If
ElseIf ctrl.Name Like "List*" Then ' User clicked an individual event in a listbox
g_strList = ctrl.Name
If ctrl.ItemsSelected.Count > 0 Then
g_AddEvent = False
For Each varItm In ctrl.ItemsSelected
strCriteria = "[EventID] = " & ctrl.ItemData(varItm)
If g_AllRights Then
DoCmd.OpenForm "frmCalDetail", , , strCriteria
Else
DoCmd.OpenForm "frmCalDetail_Read", , , strCriteria
End If
Next varItm
End If

End If

End Sub


What is going on here?

Thanks,
enak
 
I don't think you can run a sub that way. You can either change the sub to a function and append parenthesis to the end of the line:

=ShowDaysEvents()

Or you can use VBA code in the event procedure for the click event of the listbox. To do that, delete the "=ShowDaysEvents" and then click on the Build button to the right of that line in the properties window. Choose "Code Builder" and you will be taken to the VBE window.

You should be in the pre-created Click event for the listbox, so just insert the line:

ShowDaysEvents


That will run the procedure propertly.
 
Thanks for the reply. I tried both of your suggestions and got the same error:

"The expression you entered requires the control to be in the active window."

The action will open a new window.
 
This is the line that it is failing on:

Set ctrl = Screen.ActiveControl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top