BAPI-VB Connect Error

Advertisement
Hi Experts
I have used the following code which gives error in the line
If con.logon(0, False) True Then.
whats the reason, can anyone explain and correct me.
Regards
Rajaram
Private Sub Command1_Click()
Set bapictrl = CreateObject("SAP.BAPI.1")
Set con = bapictrl.Connection
con.Client = "391"
con.User = "sap01"
con.password = "victory"
con.Language = "EN"
If con.logon(0, False) True Then
MsgBox "No connection to R/3!"
Exit Sub 'End program
Else
MsgBox "connection to R/3 Successful!"
End If
End Sub
Private Sub Command2_Click()
Dim x As String
Set Obj = bapictrl.GetSAPObject("ZEMPLOYEE")
Set Header = bapictrl.DimAs(Obj, "ZBAPIEMP", "EMPDB")
Set sreturn = bapictrl.DimAs(Obj, "ZBAPIEMP", "Return")
Header.Value("code") = TextBox1.Text
Header.Value("name") = TextBox2.Text
Header.Value("salary") = TextBox3.Text
Obj.zbapiemp EMPDB:=Header, RETURN:=sreturn
x = sreturn.Value("message")
If x = "" Then
MsgBox "Created Successfully........"
Else
MsgBox x
End If
End Sub
Private Sub Command3_Click()
End
End Sub
Advertisement

Replay

Hi,
Go Through the Follwing Code:
INCLUDE BAPI OBJECT FROM REFRENCES FIRST.
Code
Option Explicit
Dim functionCtrl As Object
Dim sapConnection As Object
Dim theFunc As Object
Dim PoNumber
Private Sub Command1_Click()
Set functionCtrl = CreateObject("SAP.Functions")
Set sapConnection = functionCtrl.Connection
sapConnection.Client = "500"
sapConnection.user = "USERNAME"
sapConnection.password = "PASSWORD"
sapConnection.Language = "EN"
If sapConnection.logon(0, False)  True Then
    MsgBox "No connection to R/3 System"
    Exit Sub                                           'End program
End If
Set theFunc = functionCtrl.Add("BAPI_PO_CREATE")
Dim poheader As Object
Dim poitems As Object
Dim poitemschedule As Object
Dim retMess As Object
Dim returnFunc As Boolean
Dim startzeil As Integer
Dim endcol As Integer
Dim the_name As String
Set poheader = theFunc.exports.Item("PO_HEADER")
Set poitems = theFunc.tables.Item("PO_ITEMS")
Set poitemschedule = theFunc.tables.Item("PO_ITEM_SCHEDULES")
poheader.Value("VENDOR") = Text1.Text
poheader.Value("PURCH_ORG") = Text2.Text
poheader.Value("PUR_GROUP") = Text3.Text
poheader.Value("DOC_TYPE") = Text4.Text 
poitems.Rows.Add
poitems.Value(1, "PUR_MAT") = Text5.Text
poitems.Value(1, "PLANT") = Text6.Text
poitems.Value(1, "NET_PRICE") = Text7.Text 
poitemschedule.Rows.Add
poitemschedule.Value(1, "DELIV_DATE") = Text8.Text
poitemschedule.Value(1, "QUANTITY") = Text9.Text 
returnFunc = theFunc.call
PoNumber = theFunc.imports("PURCHASEORDER")
Set retMess = theFunc.tables.Item("RETURN")
If retMess Is Nothing Then
MsgBox retMess.Value(1, "MESSAGE")
Else
MsgBox "Purchase Order No : " & PoNumber & "Created"
End If
End Sub
Hope it will solve your problem.
Thanks
Rajesh Kumar