AAlpha1
asked on
Refresh Form - Runtime error 424 Object Required
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
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
Test1-mdb.mdb
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
use this
Public Sub FormRefreshTest2()
Call FormRefreshTest(Forms("fEx perts"))
End Sub
Public Sub FormRefreshTest2()
Call FormRefreshTest(Forms("fEx
End Sub
ASKER
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.
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.
<I want to refresh. >
Just wondering since you had "requery" in the remark:
ctlObject.Refresh ' Requery source of data for Form.
Just wondering since you had "requery" in the remark:
ctlObject.Refresh ' Requery source of data for Form.
ASKER
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
thenelson (string) approach is more versatile and "idiot proof" for people like me.
Thank you both very much.
Albert
Test1-mdb.mdb
You're welcome. Glad to help and thank you very much for the points with "A" grade!
Happy Computing!
Nelson
Happy Computing!
Nelson
ASKER
Test1-mdb.mdb