Share via

Runtime Error 2465

Anonymous
2011-02-06T11:24:31+00:00

I'm trying to set the FontName of the list boxes that I have on several of my forms by calling a public function from the OnLoad of my forms.

The following code is recieving a "Run-time error 2465: Application-defined or object-defined error"

Public Function ListBoxProperties(frm As Form)

     Dim ctl As Control

     For Each ctl In frm.Controls

         If frm.ControlType = acListBox Then

            ctl.FontName = "Arial"

         End If

     Next ctl

End Function

The For Each line is being highlighted. The forms contain only 1 listbox. I'm callong the finction form the OnLoad- Call ListBoxProperties(Me)

James

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2011-02-06T18:42:23+00:00

Public Sub ListBoxProperties(frm As Form)

    Dim ctl As Control

     For Each ctl In frm.Controls

         If ctl.ControlType = acListBox Then

            ctl.FontName = "Arial"

         End If

     Next ctl

End Sub


Cheers, Jörn Bosse

Microsoft Studentpartner

Was this answer helpful?

0 comments No comments

14 additional answers

Sort by: Most helpful
  1. Anonymous
    2011-02-06T13:08:40+00:00

    I copied and pasted your example and I'm getting the same error. I'm calling the Sub form the Onload of the form.

    James

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2011-02-06T12:59:53+00:00

    Hi,

    first off: you don´t use a return value  for your function. that´s why you can use a sub instead of a function.

    You may try something like this:

    Public Sub ListBoxProperties(mForm As Form)

         Dim ctl As Control

        Dim frm as Form

        Set frm = mForm

         For Each ctl In frm.Controls

             If frm.ControlType = acListBox Then

                ctl.FontName = "Arial"

             End If

         Next ctl

    End Sub

    And then call it with:

    Call ListBoxProperties(Me)


    Cheers, Jörn Bosse

    Microsoft Studentpartner

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2011-02-06T11:48:36+00:00

    When I set the operator Set frm = Me in the public function I get invalid use of property, of course. But when I use it in the form's OnLoad I get variable not defined, of course.

    Where might I use this. I realy didn't think I needed to since I'm placing the 'Me' in the function arguments when I call the function

    James

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2011-02-06T11:33:38+00:00

    Hello

    Did you use the Set-Oprator to set the form?

    For example:

    Set frm = Me


    Cheers, Jörn Bosse

    Microsoft Studentpartner

    Was this answer helpful?

    0 comments No comments