Solved

Refresh Form - Runtime error 424 Object Required

Posted on 2009-07-15
8
426 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 119

Assisted Solution

by:Rey Obrero
Rey Obrero 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
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 24864225
use this

Public Sub FormRefreshTest2()

    Call FormRefreshTest(Forms("fExperts"))

End Sub
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
is there a opposite on ON CURRENT in ms/access 15 32
ms/access hyperlink/ftp 7 34
format date field on certain entries 8 27
Access 2010 Query Syntax 5 18
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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…

919 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now