Skip to Content
Former Member
Jan 12, 2007 at 07:06 PM

BAPI_USER_CHANGE "named argument not found" error in VBA



I'm trying to update SAP users' email addresses en masse via a VBA routine. The subroutine I'm trying to run is here, at least in skeletal form (it still needs MAPI code to pick up the email information, but that's outside the scope of the question:)

Sub UpdateUsers()

Dim gConnection As Object 'global connection object

Dim boUser As Object

Dim oAddress As Object, oPOHeader As Object, oAddressX As Object, oReturn As Object

Dim oCommitReturn As Object, oBAPIService As Object

Dim db As Database, rs As Recordset

Dim strDbName As String

Dim oBAPICtrl As New SAPBAPIControl

'Database file name

strDbName = CurrentDb.Name

'Open database file

Set db = DBEngine.OpenDatabase(strDbName)

'Database table/query to take data from

Set rs = db.OpenRecordset("users", dbOpenDynaset, dbSeeChanges)

'Set up connection object for SAP. Note that the SAP BAPI ActiveX object must be available on the form or otherwise.

Set gConnection = oBAPICtrl.Connection

'Log in to SAP. Seems like passwords must be in uppercase. There are examples of people defaulting some (or all)

'of the login values


'Set up the transaction commit. You need this for the effects of an update BAPI to actually take effect.

Set oBAPIService = oBAPICtrl.GetSAPObject("BapiService")

'This table object contains error message data regarding how well the commit worked.

Set oCommitReturn = oBAPICtrl.DimAs(oBAPIService, "TransactionCommit", "Return")

'Buzz through the Access table.

With rs


Do While .EOF <> True

'Initialize all BAPI objects for each transaction.

Set boUser = Nothing

Set oPOHeader = Nothing

Set oAddress = Nothing

Set oAddressX = Nothing

Set oReturn = Nothing

'Initialize all BAPI object structures to what is required.

'To see what BAPI's are available and how to call them, go to

'Note that the first line actually establishes a primary key (PO, in this example.)

Set boUser = oBAPICtrl.GetSAPObject("USER", !Uname)

Set oAddress = oBAPICtrl.DimAs(boUser, "Change", "Address")

Set oAddressX = oBAPICtrl.DimAs(boUser, "Change", "Addressx")

Set oReturn = oBAPICtrl.DimAs(boUser, "Change", "Return")

'Populate all tabular BAPI structures with appropriate information, as required by the BAPI.

' oAddress.rows.Add

oAddress.Value("E_MAIL") = ""

' oAddressX.rows.Add

oAddressX.Value("E_MAIL") = "X"

'Actually call the BAPI here.

boUser.Change UserName:=!Uname, _

Address:=oAddress, _

Addressx:=oAddressX, _


'See how things worked by checking the first line of the "return" object. Type code of "S" means success.

If oReturn.Value(1, "TYPE") <> "S" Then

'If we had a non-successful return code, pop up a message box here indicating what went wrong.

MsgBox ("Error changing user" + !User + vbCrLf + oReturn.Value(1, "MESSAGE"))


'If we received a successful return code, do a commit. You have to do this in order for the update to work.

oBAPIService.TransactionCommit Wait:="X", _



!done = True


End If



End With

'Log out of SAP.


MsgBox ("Done.")

End Sub

Can anyone see what's going on with the BAPI call to BAPI_USER_CHANGE and what I'm not providing it that it wants (or am providing it wrong?)