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-06T18:41:11+00:00

    I was just getting ready to paste this 'cause it worked. I was checking one of my Access books.

    Now, how might apply this to all my forms using a Public Function. That is however my goal.

    Public Sub ListBoxProperties(frm As Form)

        Dim ctl As Control

        Set frm = Me

         For Each ctl In frm.Controls

             If ctl.ControlType = acListBox Then

                ctl.FontName = "Arial"

             End If

         Next ctl

    End Sub

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2011-02-06T18:39:24+00:00

    omg i´m so sorry!

    If ctl.ControlType = acListBox Then

                ctl.FontName = "Arial"

             End If

    you want to check the controltype so you have to use ctl.ControlType

    Sorry, i should have seen this at the beginning.


    Cheers, Jörn Bosse

    Microsoft Studentpartner

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2011-02-06T18:14:20+00:00

    Same error message (2465). If frm.ControlType... is highlighted.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2011-02-06T16:56:08+00:00

    Now use this code instead of msgbox ctl.cname

             If frm.ControlType = acListBox Then

                ctl.FontName = "Arial"

             End If


    Cheers, Jörn Bosse

    Microsoft Studentpartner

    Was this answer helpful?

    0 comments No comments