Share via

How to fix the code with Run Time Error: '424': Object required?

Anonymous
2018-07-14T17:06:33+00:00

Hi experts!

I have a listbox name lstRprt that displays all my Query in a Form.

On a click from my cmdAddRprt it would correlate or transfer Query Names to my next listbox name lstToEprtafter  a select from my lstRprt.

After a click on my cmd button I have an Error: '424': Object required ask me to debug the code below;


Dim RowSource As String

     Set db = CurrentDb()

    Set rs = db.OpenRecordset("SELECT Asset.* FROM Asset")

    RowSource = ""

    Do Until rs.EOF

        RowSource = "SELECT * FROM Asset"

        rs.MoveNext

    Loop

    lbox1.RowSource = RowSource     <<<<<<< it highlights here

    RowSource = ""

    Set rs = db.OpenRecordset("SELECT Asset.* FROM Asset ORDER BY [Name]")

    Do Until rs.EOF

        RowSource = RowSource & rs!empid & ";" & rs!Name & ";"

        rs.MoveNext

    Loop

   lbox2.RowSource = RowSource

Please anyone is kind to help me what was wrong and correct it??

thanks in advance, Rev12

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

1 answer

Sort by: Most helpful
  1. Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
    2018-07-14T18:18:35+00:00

    The message indicates Access does not know what lbox1 is. Maybe the previous name of a listbox?

    On the highlighted line, replace lbox1 with:

    Me.lstRprt 

    or

    Me.lstToEprt

    Review the line with lbox2 as well. It is about to fail the same way.

    Did you not have "Option Explicit" at the top of every module in your code? Add it right now.

    There are other things wrong with this code, such as the nonsensical first Do loop.

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments