Solved

Refresh Form - Runtime error 424 Object Required

Posted on 2009-07-15
8
461 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 200 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 300 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

728 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