Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble trying to requery subform field

Status
Not open for further replies.

jtwardowski

Technical User
Apr 15, 2004
3
US
Hello,
I am a novice at using VB. I took a class a few years ago and have not used it since. I am using Access 2002 and I am trying to requery a field in my subform after a field in my main form is updated. I figured an AfterUpdate Event Procedure would be appropriate, but not quite sure how to do it. My main form is called frm_Sheet_Information and my subform is called sfrm_Treatment_Data. The field I want to trigger the event on the main form is Zone and the field I want to requery on the subform is Unit. I tried to create some code, but when I ran it, it asked for a macro so now I have the following which results in a Runtime error 2465: Application defined or object defined error. The debug feature says it is in the mac_units subroutine.

Private Sub Zone_AfterUpdate()

DoCmd.OpenForm "sfrm_Treatment_Data"

Dim rst As Recordset
Set rst = [frm_Treatment_Data Subform].Unit

mac_units

End Sub

Sub mac_units()
Forms.frm_Sheet_Information.sfrm_Treatment_Data.Unit.Requery
End Sub

I'm sorry to bother you with what is probably a simple problem.

Any input would be appreciated.
Thanks,
Julie
 
hi

You are close

Me.sfrm_Treatment_Data.FORM!Unit.Requery

assuming sfrm_Treatment_Data is the name of the SUBFORM CONTROL

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Thank you for responding. I tried replacing

Forms.frm_Sheet_Information.sfrm_Treatment_Data.Unit.Requery

with

Me.sfrm_Treatment_Data.FORM!Unit.Requery

and got a message saying Compile error: Invalid use of Me keyword. Since you said it had to me the name of the control, I then tried putting the name of the field in and got the same error. Did I put the line in the wrong place - should it be in a Macro? Asking because the debugger highlighted the Sub mac_units().

Thanks again.
 
I think you can try Forms!frm_Sheet_Information!sfrm_Treatment_Data!Unit.Requery

-Laughter works miracles.
 
Hi

I assumed, (wrongly) that code was in the main form module, so Me. would be OK, if it is not you need Forsm!Formname type syntax

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top