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-06T16:19:04+00:00

    Ok. Each message box returned all control names on the form including the List Box

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2011-02-06T16:07:00+00:00

    Thats why i wrote that you have to copy this code into a form module and not a normal module.


    Cheers, Jörn Bosse

    Microsoft Studentpartner

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2011-02-06T15:46:09+00:00

    The 'Set frm = Me' triggers an 'Invalid use of the Me keyword' in a procedure outside a form.

    James

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2011-02-06T13:25:35+00:00

    Okay i just tried the following:

    Public Sub ListBoxProperties(frm As Form)

         Dim ctl As Control

        Set frm = Me

         For Each ctl In frm.Controls

             MsgBox ctl.Name

         Next ctl

    End Sub

    Private Sub Form_Load()

    Call ListBoxProperties(Me)

    End Sub

    Copy this code to your Form and tell me if it worked.


    Cheers, Jörn Bosse

    Microsoft Studentpartner

    Was this answer helpful?

    0 comments No comments