cancel
Showing results for 
Search instead for 
Did you mean: 

Update Bill To address when Transaction exist into data base against the BP

Former Member
0 Kudos

Hello,

i am trying update BP default Bill To address:

Code is:

vBP = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners)

If (vBP.GetByKey(SCID) = True) Then

vBP.CardCode = SCID

vBP.FederalTaxID = TaxId

vBP.CardName = Customer1

Call vBP.ContactEmployees.Add()

Call vBP.ContactEmployees.SetCurrentLine(0)

If Contact <> "" Then vBP.ContactEmployees.Name = Contact

If PhoneNum <> "" Then vBP.Phone1 = PhoneNum

If FaxNum <> "" Then vBP.Fax = FaxNum

If AfterHoursNum <> "" Then vBP.Phone2 = AfterHoursNum

If MailAddress1 <> "" Then

vBP.Addresses.AddressType = SAPbobsCOM.BoAddressType.bo_BillTo

vBP.Addresses.SetCurrentLine(0)

vBP.Addresses.Street = MailAddress1

vBP.Addresses.AddressName = Customer1

vBP.Addresses.Block = MailAddress2

vBP.Addresses.ZipCode = MailZiP

vBP.Addresses.State = MailState

vBP.Addresses.City = MailCity.Replace("-", " ")

End If

If (0 <> vBP.Update())

Call oCompany.GetLastError(nErr, errMsg)

....

But it makes a new Bill to address instead of updating the address.

I am working on 2007A PL 45.

Thanks & Regards

vinit kumar

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

I am using this code :

Dim vBP As SAPbobsCOM.BusinessPartners

vBP = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners)

If (vBP.GetByKey(SCID) = True) Then

For i = 0 To vBP.Addresses.Count - 1

vBP.Addresses.SetCurrentLine(i)

If vBP.Addresses.AddressType = SAPbobsCOM.BoAddressType.bo_BillTo Then

If vBP.BilltoDefault = vBP.Addresses.AddressName Then

vBP.Addresses.AddressName= "new Name"

vBP.Addresses.City = MailCity

vBP.Addresses.Street = MailAddress1

vBP.Addresses.ZipCode = MailZiP

AddT = vBP.Update()

If (0 <> vBP.Update()) Then

Call oCompany.GetLastError(nErr, errMsg)

End If

End If

End If

Next

End If

Thanks

vinit kumar

Former Member
0 Kudos

Vinit,

is it required to change the Addressname?

the following line


vBP.Addresses.AddressName= "new Name"

actually addes a new entry. if you remove this, it will update the existing one. I think you can either change all other properties of existing addresses or create a new one with a new Address Name.

regards,

Binita

Former Member
0 Kudos

Thanks for quick reply.

But my problem is not solved i use your method.

Actually in my case each customer have only one Bill to address. I am updating the address name with the customer name and new Bill to address is created not updated the existing addres.

If there is no tranaction against this BP into database this works fine but if some transaction exist into database then it makes new Bill To address.

Thanks

vinit kumar

Former Member
0 Kudos

Vinit,

post the code you have used. the modified one.

Binita

Former Member
0 Kudos

Vinit,

try this:


 Dim vBP As SAPbobsCOM.BusinessPartners
        vBP = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners)
        If (vBP.GetByKey(SCID) = True) Then
            For i = 0 To vBP.Addresses.Count - 1
                vBP.Addresses.SetCurrentLine(i)
                If vBP.Addresses.AddressType = SAPbobsCOM.BoAddressType.bo_BillTo Then
                    If vBP.BilltoDefault = vBP.Addresses.AddressName Then
                        vBP.Addresses.City = "city new"
                        vBP.Addresses.Street = "street new"
                        AddT = vBP.Update()
                        If AddT <> 0 Then
                            oCompany.GetLastError(lErrCode, sErrMsg)
                            MsgBox(sErrMsg)
                        End If
                    End If
                End If
            Next
        End If

I have mentioned just two properties. you can modify it as per your requirement.

hope it will help,

Binita