0

I'm having a problem with the SAP RFC when I'm trying to download some tables. When I try to create the connection I get the following error:

Bad Variant Type

I checked the regedit registry for RFC and it is all right.

The IT installed the SAP 7.50, but I'm unable to use such version cause it does not allow me to download some tables that I need, so I asked them to make the downgrade to the 7.40 version of SAP.

The problem started just there.

Public Sub conecta_sap()

Set ctlLogon = CreateObject("SAP.LogonControl.1")
Set funcControl = CreateObject("SAP.Functions")
Set ctlTableFactory = CreateObject("SAP.TableFactory.1")
Set objWindowsScriptShell = CreateObject("WScript.Shell")
Set objConnection = ctlLogon.NewConnection
    
objConnection.ApplicationServer = "XXXXXXXXXX"
objConnection.SystemNumber = "30"
objConnection.Client = "300"
objConnection.Language = "PT"
objConnection.USER = "RFC_LANCO"
objConnection.Password = "XXXXXXXX"
booReturn = objConnection.logon(0, True)
    
If booReturn <> True Then
    MsgBox "Impossível conectar no SAP!"
    End
End If

funcControl.Connection = objConnection
Set RFC_READ_TABLE = funcControl.Add("RFC_READ_TABLE")
Set strExport1 = RFC_READ_TABLE.exports("QUERY_TABLE")
Set strExport2 = RFC_READ_TABLE.exports("DELIMITER")
Set tblOptions = RFC_READ_TABLE.Tables("OPTIONS")
Set tblData = RFC_READ_TABLE.Tables("DATA")
Set tblFields = RFC_READ_TABLE.Tables("FIELDS")
    
End Sub

When I reach this line:

funcControl.Connection = objConnection

I get the following error:

Erro em tempo de execução '-2147352568 (80020008)': Bad variant type

Can anyone help me solve this problem?

Thank you!

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
zanniboni
  • 13
  • 5
  • 1
    Where is `objConnection` and `funcControl` declared? Should they be `Objects` or `Variants`? – Ryan Wildry Jun 05 '19 at 13:47
  • I have tried to declare then as Objects and Variants and the error persists... – zanniboni Jun 05 '19 at 13:48
  • 1
    Maybe this will help. https://blogs.sap.com/2007/12/12/accessing-sap-functions-from-excel-using-visual-basic-applications/ – Ryan Wildry Jun 05 '19 at 13:53
  • Please let me know if I'm breaking the SO rules here. I'm trying to create traffic on my question by posting a link to it within a related question. I'm hoping we can all solve this problem regardless of programming environment. [link](https://stackoverflow.com/questions/58942674) – MBB70 Nov 20 '19 at 14:55

0 Answers0