?
Solved

Refresh Form - Runtime error 424 Object Required

Posted on 2009-07-15
8
Medium Priority
?
482 Views
Last Modified: 2013-11-28
I use a function to refresh a form. It can be accessed from other modules or from the Form itself.
The form requires the form name to be explicitly defined as shown in the "Code that works"

I would like to have a more general function where I pass the form name to the function as an argument. This is shown in the "Code that is not working". The name of the form is defined in the sub that's calling the function. It generates a runtime error 424 Object required.

Is what I'm trying to do achievable?

Thanks


' Code that works:
Function FormRefresh()
    Dim ctlObject As Form
    Set ctlObject = Form_fExperts      ' EXPLICITLY Define Form to refresh
    ctlObject.Refresh                  ' Requery source of data for Form.
            MsgBox ("Done")
End Function
'
' Code that is not working
Function FormRefreshTest(FormName)
    Dim ctlObject As Form, vFormName   
    vFormName = ("Form_" & FormName)
    Set ctlObject = vFormName             ' Define Form to refresh
    ctlObject.Refresh                            ' Requery source of data for Form.
        MsgBox ("Test Done")  
End Function

Open in new window

Test1-mdb.mdb
0
Comment
Question by:AAlpha1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 800 total points
ID: 24863712
test this

Private Sub RefreshTest_Click()

    Call FormRefreshTest(Me)
   
End Sub


' -------------------------------------------------------------------
' Refresh Form Test
'
' -------------------------------------------------------------------
Function FormRefreshTest(FormName As Form)
   
    Dim ctlObject As Form
   
    Set ctlObject = FormName            ' Define Form to refresh
    ctlObject.Refresh                    ' Requery source of data for Form.

        MsgBox ("Test Done")
   
End Function
0
 
LVL 39

Accepted Solution

by:
thenelson earned 1200 total points
ID: 24863900
Cap's answer or pass the form name as a string:

Function FormRefreshTest(FormName As String)
    Forms(FormName).Refresh                          
        MsgBox ("Test Done")  
End Function

Do you want to refresh or requery the form?
0
 

Author Comment

by:AAlpha1
ID: 24864129
Brilliant. It works when called from the form. But, it does not work when called from a module (invalid use of Me key word) . On another form, that form is refreshed but not any other one.
Test1-mdb.mdb
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24864225
use this

Public Sub FormRefreshTest2()

    Call FormRefreshTest(Forms("fExperts"))

End Sub
0
 

Author Comment

by:AAlpha1
ID: 24864244
Capricorn1: My response (07/15/09 02:00 PM, ID: 24864129) was for your proposal. I apologize for not addressing it properly.

the Nelson: I want to refresh. I suppose if I wanted to requery, I would replace the .Refresh with .Requery. I am now testing your proposal.
0
 
LVL 39

Expert Comment

by:thenelson
ID: 24864422
<I want to refresh. >
Just wondering since you had "requery" in the remark:
    ctlObject.Refresh                  ' Requery source of data for Form.
0
 

Author Comment

by:AAlpha1
ID: 24864825
Capricorn1 "Me" method is great provided it's used locally in the form calling the Refresh action.
thenelson (string) approach is more versatile and "idiot proof" for people like me.

Thank you both very much.
Albert
Test1-mdb.mdb
0
 
LVL 39

Expert Comment

by:thenelson
ID: 24864845
You're welcome.  Glad to help and thank you very much for the points with "A" grade!

Happy Computing!

Nelson
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Suggested Courses
Course of the Month13 days, 2 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question