cancel
Showing results for 
Search instead for 
Did you mean: 

Logon with VBA without Logon window.

Former Member
0 Kudos

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 = "192.168.2.219"

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?

Accepted Solutions (0)

Answers (1)

Answers (1)

swapnapriya_neemkar2
Active Participant
0 Kudos

Hi,

Refer to below link as to how we can use the "True" option of oBapiCtrl.Connection.Logon() method for doing a Silent Logon into the SAP system.

[http://klanguedoc.hubpages.com/hub/Silent-Connection-with-SAPLOGON-with-RFCSDK-Example-RFC-Excel-VBA]

In your code the IF Statement with "True" value passed to oBapiCtrl.Connection.Logon() should check for the result to be NOT EQUAL to True for exiting the process.

Hope this helps.

Thanks,

Swapna Priya.

Former Member
0 Kudos

Hi, Thanks for this answer.

But I undedrstand that part.

I tried to make clear: I can connect with logon screen, but with the same settings (and parameters) I cannot connect without the logon screen.

The only change I make is the ...logon (1,true)....

Is it possible to debug this by an error code or something?

Or is there a setting necessary in the account settings?

Edited by: foosterhuis on Feb 4, 2012 11:32 AM

swapnapriya_neemkar2
Active Participant
0 Kudos

Hi,

The code pasted doesn't clearly indicate the IF statement's operator. Also if we see below details posted, understanding went as that Code is exiting when the IF statement result is TRUE. Hence suggested to check for not equal to TRUE condition.

"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?

"

If the logon is successful with logon pop-up then it should also by silent logon.

Below is another forum post for same issue. This is also highlighting that this could also be issue due to the ways the host is accessible - through direct network or through VPN based connection.

[;

And see if below link helps for debugging the VBA code.

[http://wiki.sdn.sap.com/wiki/display/BOBJ/Tipsfortroubleshootingordebugging]

Thanks,

Swapna Priya.