Macro to get a grid field value for the current record on a subform

I have this which works fine for a grid field on a MAIN form

public function getMainformGridField(theEvent as object, FieldName as string) as variant
dim rowset 	as object
dim Form 	as object

	Form=theEvent.Source.Model.Parent
	rowset=Form.getColumns
	getMainformGridField=rowset.getbyName(FieldName).value
end function

have tried this for a subform

public function getSubFormGridField(theEvent as object, FieldName as string) as variant

dim oMainForm		as object
dim oColumnList	as object 
dim oGrid			as object
dim theValue 		as variant

	oMainForm=theEvent.Source.Model.Parent
    oGrid=oMainForm.getbyName("SubForm_Grid")
    oColumnList = oGrid.getByName(FieldName)
    theValue=oColumnList.getCurrentValue()
    getSubFormGridField=theValue
end function

But it fails at the oColumnList assignment.

Can anyone help with the correct code please?

With a bit of experimentation I’ve sorted it and discovered a working solution

public function getSubFormGridField(theEvent as object, FieldName as string) as variant
dim oMainForm		as object
dim oSubform	as object
dim oColumnList	as object 
dim oGrid			as object
dim theValue 		as variant

	oMainForm=theEvent.Source.Model.Parent
	oSubform=oMainForm.getbyName("SubForm")
    oGrid=oSubForm.getbyName("SubForm_Grid")   
    oColumnList = oGrid.getByName(FieldName)   
    theValue=oColumnList.getCurrentValue()
    getSubFormGridField=theValue
end function

Thanks for posting this solution. Getting the value of a subform field has proven difficult. I have my own solution, but it is good to see other solutions too for future reference.