Skip to Content
Former Member
Feb 03, 2012 at 12:53 PM

Logon with VBA without Logon window.


I connect via VBA to SAP R/3 with the follwing code (example parameters)

Dim oBapiCtrl As Object

Dim oBapiLogon As Object

Dim oData As Object

Dim oItem, oReturn As Object

Dim iIndex As Integer

Dim oTable As Object

Set oBapiCtrl = CreateObject("sap.bapi.1")

Set oBapiLogon = CreateObject("sap.logoncontrol.1")

oBapiCtrl.Connection = oBapiLogon.NewConnection

oBapiCtrl.Connection.ApplicationServer = ""

oBapiCtrl.Connection.System = "TRN"

oBapiCtrl.Connection.Client = "600"

oBapiCtrl.Connection.User = "xcom"

oBapiCtrl.Connection.Password = "abcdef"

oBapiCtrl.Connection.Language = "EN"

oBapiCtrl.Connection.SystemNumber = "00"

If oBapiCtrl.Connection.Logon(0, True) True Then

MsgBox "not connected", vbInformation, "SAP Logon"

Exit Sub

End If

Is it possible to get an error from the logon statement?

Because when I use oBapiCtrl.Connection.Logon(0, False) I can logon to the SAP environment. The If statement is false.

But when I use oBapiCtrl.Connection.Logon(0, True), I can't. The If statement is true and the code will exit in de If statement.

Those anybody now how can we solve this problem?