cancel
Showing results for 
Search instead for 
Did you mean: 

How do I get the contact person name from a saleorder

Former Member
0 Kudos

I am getting the contactpersoncode from the saleorder using

ContactPersonCode = salesorder.ContactPersonCode

this is a text number '31'

but as there is onle one contact person on the bus Partner record I get an exeption when using


  oBpEmp = oBP.ContactEmployees
  oBpEmp.SetCurrentLine(CInt(ContactPersonCode) - 1)

Am I using this code correctly? any pointers?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi there,

Why don't you try using recordset?

ors.doquery("Select Name from OCPR Where CntctCode='" & ContactPersonCode & "'")

Then you can put your Contact Person Name Variable = ors.Fields.Item(0).Value

Quite Simple... Save you some process time from looping function.

You can use for other purpose also...

Message was edited by: Erik Tang

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanks Adele, You have cleared up my confusion on how the contacts were organised.

And Thanks Also to Erik you have provided the solution

Regards George..

Former Member
0 Kudos

Hi George,

The SetCurrentLine method and the ContactEmployee number does not work together. For each business partner the SetCurrentline runs from 0 (zero) to the number of contacts -1 (minus 1). Say this is what your business partner looks like:

<u>C1000</u>

1-George

4-Jack

5-Jill

31-The One you want

If your code looks like this (to get the one you want):

oBp.GetByKey("C1000")
oBpEmp = oBp.ConactEmployees
oBpEmp.SetCurrentLine(31-1)

You'll get an error as it should actually be

oBpEmp.SetCurrentLine(3)

The only way I can think of solving your problem right now is if you loop through all the contact employees of that specific business partner like:

        Dim i As Integer
        For i = 0 To oBp.ContactEmployees.Count - 1
            oBpEmp.SetCurrentLine(i)
            If oBpEmp.InternalCode = ContactPersonCode Then
                MessageBox.Show(oBpEmp.Name)
                'do your thing...
            End If
        Next

Hope this helps,

Adele