Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Excel AP:Add Distribution Code 1

Status
Not open for further replies.

Justin9999

Programmer
Joined
Aug 4, 2011
Messages
2
Location
AU
Hi,

Can anyone tell whats wrong with this code? I have added a reference to "ACCPAC COM API Object 1.0". It seems to opening the session ok.

Public Sub Add_Dist_Code(DistCode As String, glAccount As String, Description As String)
'
' Recorded at: Fri Aug 05 13:47:18 2011
'
Dim Session As AccpacCOMAPI.AccpacSession
Set Session = CreateObject("Accpac.Session")


'Open accpac session
Session.Init "", "AS", "AS9031", "56A"
Session.Open "JUSTIN", "whatever", "ANGDAT", Date, 0, ""

On Error GoTo ACCPACErrorHandler

' TODO: To increase efficiency, comment out any unused DB links.
'HAS A PROBLEM WITH LINE BELOW **********************************
Dim mDBLinkCmpRW As AccpacCOMAPI.AccpacDBLink
Set mDBLinkCmpRW = OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE)

Dim mDBLinkSysRW As AccpacCOMAPI.AccpacDBLink
Set mDBLinkSysRW = OpenDBLink(DBLINK_SYSTEM, DBLINK_FLG_READWRITE)

Dim temp As Boolean
Dim APDISTCODE1 As AccpacCOMAPI.AccpacView
Dim APDISTCODE1Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "AP0005", APDISTCODE1
Set APDISTCODE1Fields = APDISTCODE1.Fields


APDISTCODE1.Init

APDISTCODE1Fields("DISTID").Value = DistCode ' Distribution Code

temp = APDISTCODE1.Exists

APDISTCODE1Fields("IDGLACCT").Value = glAccount ' G/L Account
APDISTCODE1Fields("TEXTDESC").PutWithoutVerification (Description) ' Description
APDISTCODE1Fields("SWDISCABL").PutWithoutVerification ("0") ' Discountable

APDISTCODE1.Insert


Exit Sub

Thanks in advance for any help.

Justin
 
Set mDBLinkCmpRW = Session.OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE)
 
Also you can clean up your code by removing all lines that reference 'temp'.

If at first you don't succeed, then sky diving wasn't meant for you!
 
Thanks everyone. Works a treat!

Justin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top