Showing results for 
Search instead for 
Did you mean: 

Cannot remove user define fields

Former Member
0 Kudos


I am trying to remove a user defined field (U_Prirev) in Table (OHEM) and am getting the following error:

Ref count for this object in higher then 0. Error No -1120

The code is as follows :

Dim sRequete As String

Dim errCode As Long

Dim errMsg As String

Dim IdField As Integer

Dim oUFields As SAPbobsCOM.UserFieldsMD

oUFields = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)

Dim oRecordSet As SAPbobsCOM.Recordset

oRecordSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

sRequete = "SELECT FieldID FROM CUFD where TableId = '" & pNomTable & _

"' and AliasID = '" & pNomChamp & "'"


If (oRecordSet.EoF = False) Then

IdField = CType(oRecordSet.Fields.Item(0).Value, Integer))

If (oUFields.GetByKey(pNomTable, IdField) = True) Then

If (oUFields.Remove() <> 0) Then

oCompany.GetLastError(errCode, errMsg)

Console.WriteLine("Erreur => Code = " & errCode.ToString + " Message = " + errMsg)

End If

End If

End If


oRecordSet = Nothing

End Sub

Anyone knows why i am getting this error.



Accepted Solutions (1)

Accepted Solutions (1)

Active Contributor
0 Kudos

Hi Laurent

That error you are getting is the error that you get is when there is more than one instance of meta data object open. You see only one metedata object can be open at a time.....if it's higher than zero it means others are available. I see you have,


oRecordSet = Nothing

this is good and what closes the meta data object. But check that you have done this in previous funtions where you might of added other things.Also your recordset, close it before adding.....move oRecordSet = Nothing to before your Remove of the field. that has be the case for me before. Do it without the recordset as a test and you'll see it works.

Hope it helps

Answers (1)

Answers (1)

0 Kudos

I would suggest the following lines whenever you are done with usage of COM (SAPbobsCOM) objects:

' First reset to null all references to consumed SAPbobsCOM objects (like you did for oRecordSet = Nothing)