Solved

Refresh Form - Runtime error 424 Object Required

Posted on 2009-07-15
8
432 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
  • 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
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…

770 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