cancel
Showing results for 
Search instead for 
Did you mean: 

Microsoft VBA - "Can't assign to read-only property"

Former Member
0 Kudos

Hi,

I'm receiving a compile error "Can't assign to read-only property" in an Excel VBA enabled workbook. The code in bold raises the compile time error.

The relevant code is:

Set oOrder = oCompany.GetBusinessObject(SAPbobsCOM.oOrders)

....

oOrder.Lines.Text = "some sample text"

Note that I can successfully update all fields on header and row level (including UDFs of type text and date) on a sales order and this is the only field that is giving problems. Additionally, this field can be updated via the UI. The field in SQL db is of type 'ntext'.

eg. oOrder.Lines.FreeText = "some sample text" works fine (100 char field, not of type ntext though).

I'm using 9.1 PL07 and SQL Server 2008 R2 SP3. This issue has also been reproduced on 8.82 (not sure of PL).

Is it fair to assume that the read-only property for this field has been incorrectly set in SAPbobsCOM ? Or do I have to use a different syntax for fields of type text?

Thank you.

Regards,

George

Accepted Solutions (1)

Accepted Solutions (1)

pedro_magueija
Active Contributor
0 Kudos

Hi George,

According to the documentation it is read-only.


Property type

Read-only property

Syntax

Visual Basic

Public Property Text() As String

What are you trying to update? The comments? That would be the FreeText property.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Former Member
0 Kudos

Hi Pedro,

I think we are talking about different Text() properties as there are at least 2 in the DI API reference. Please see below for the one I'm having an issue with. Also note that I can update this by the UI (via SAP client), as per my initial email, so that confirms it is read-write.

SAP Business One DI API 9.1 - Objects Reference (910.150)
Text Property
 

Description

The text to be saved for display in marketing documents.

The field must contain at least one non-space character and must be a valid key string (i.e., it cannot contain *,{,},%,!,^,=,<,>,?,|).

Field name: Text

Property type

Read-write property

Syntax

Visual Basic

Public Property Text() As String

I'm probably going to write some C# code to see if the issue is with VBA itself or the dll (Eric's reply indicates it may be a VBA issue).
Thanks for your response, I'm hoping to get to the bottom of this with developers such as yourself on this forum.
Kind Regards,
George

Former Member
0 Kudos

Hi George,

The fact that you can update the field thru the FAT client doesn't mean this is a read-write property for the UI-API: so Pedro and you can both be correct on this one.

After checking, according to the doc (can be wrong) and DotPeek (cannot be wrong):

  • Document_Lines.FreeText is Read-write,
  • Document_Lines.Text is read only.

So Pedro was correct and I was not.

Regards,

Eric

pedro_magueija
Active Contributor
0 Kudos

Hi George,

Did I understand correctly that you want to use the Document_Lines.Text property? If that is the case then it is read-only. However I did find the documentation you posted for the PredefinedText object. I believe this is like template text to be added by B1 to the marketing document.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Former Member
0 Kudos

Hi Pedro,

Thanks, you are correct.

I have found the entry under "Document_Lines Object Members" and it is quite clear there that it is read-only (except for the typo where it uses lowercase for the field as in "text" not "Text").

I just don't understand why we can't update this field via the DI, when we can via the fat client, and why SAP hasn't enabled this yet in the DI. Anyways, I have a workaround, so that mystery will have to remain for now.  

Thanks once again.

Kind Regards,

George

Former Member
0 Kudos

Hi Eric,

Thanks for the insight that fat client updateable doesn't necessarily mean UI API updateable and the DotPeek tool 'hint' !

Kind Regards,

George

pedro_magueija
Active Contributor
0 Kudos

Hi George,

Unfortunately it is the case with some "properties" being editable in the client and not via the API.

You can try to raise a ticket with support and tell them that you can update via the client and not the API and you see this as a "issue".

They might view it the same way and have it changed in the future.

If you do go ahead and do this, please let us know the reply.

Good luck.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Former Member
0 Kudos

Hi Pedro,

I'm unfortunately not affiliated with or registered as a SAP Partner at the moment (I'm currently working as a freelancer), so there is no possibility of me registering a support ticket, otherwise I definitely would. I'd love to assist in improving the SDK incrementally!

All the best,

George Mamacos

Former Member
0 Kudos

Hi George,

You're not alone in your situation, and you have solutions to your questions. So, not a so bad world

Regards,

Eric

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi George,

Syntax is correct and not related to the field... I'm more suspecting a VBA issue.

Since you can update UDF, may you do a test by creating one UDF of type ntext and to try to update it thry a small VBA sample?

Regards,

Eric

Former Member
0 Kudos

Hi Eric,

Can you update this field in C# or any other language, other than VBA ?

Thanks for your suggestion, I was thinking along the same lines but I have already tried it when I stated in my initial email "(including UDFs of type text and date)" , with 'text' implying 'ntext'.


Thanks once again for taking an interest in this issue.


Kind Regards,

George