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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make value from macro appear in a form

Status
Not open for further replies.

barboza

Programmer
Oct 20, 2007
7
US
I have written the following macro that is in module 1.

Sub Test()
DoCmd.SelectObject acForm, "frmCustody"
frmCustody.Me.Controls("F9").Value = "Ag"
End Sub

I get the following error: Object required.
Any ideas how to get the value to show up in the form when the macro runs??

Thanks,
B
Edit/Delete Message
 
Hi barb,

This is NOT a macro, it's VBA code (there is a BIG distinction).

I'd look at the .dot notation in this line:

frmCustody.Me.Controls("F9").Value = "Ag"

or, it seems to indicate that you have a sub-form, and if so, use MS Access Help to search for this:

"sub form reference" in order to understand how to reference subform objects.

ATB

Darrylle




Never argue with an idiot, he'll bring you down to his level - then beat you with experience.
 
Me" is used to refer to the instantiated object. In other words in a form's module "me" refers to the form. In a report's module "me" refers to the report. If you are referring to a form or report not from its own module then you can not use "Me".

So this syntax is wrong:
frmCustody.Me.Controls("F9").Value = "Ag"

If you want to refer to "frmCustody" from outside of its own module then use the forms collection:

forms("frmCustody").controls("F9").value
or using bang notation
forms!frmCustody.controls!F9.value

Not sure what you are doing, but there should be no reason to use selectObject.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top