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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PJC Macro - Accpac Sage 300 2014

Status
Not open for further replies.

ram26

Programmer
Dec 11, 2017
2
AE
I am trying to load this macro, which is recorded from Sage. However I am getting an error as Contract Number cannot be blank, Project cannot be blank.. This error comes whenever I Insert.. below is the code. Seek you help.

Program is to Insert new Material codes to the existing contract and Project

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 PMCONT1header As AccpacCOMAPI.AccpacView
Dim PMCONT1headerFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PM0021", PMCONT1header
Set PMCONT1headerFields = PMCONT1header.Fields

Dim PMCONT1detail1 As AccpacCOMAPI.AccpacView
Dim PMCONT1detail1Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PM0022", PMCONT1detail1
Set PMCONT1detail1Fields = PMCONT1detail1.Fields

Dim PMCONT1detail2 As AccpacCOMAPI.AccpacView
Dim PMCONT1detail2Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PM0039", PMCONT1detail2
Set PMCONT1detail2Fields = PMCONT1detail2.Fields

Dim PMCONT1detail3 As AccpacCOMAPI.AccpacView
Dim PMCONT1detail3Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PM0120", PMCONT1detail3
Set PMCONT1detail3Fields = PMCONT1detail3.Fields

Dim PMCONT1detail4 As AccpacCOMAPI.AccpacView
Dim PMCONT1detail4Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PM0121", PMCONT1detail4
Set PMCONT1detail4Fields = PMCONT1detail4.Fields

Dim PMCONT1detail5 As AccpacCOMAPI.AccpacView
Dim PMCONT1detail5Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PM0850", PMCONT1detail5
Set PMCONT1detail5Fields = PMCONT1detail5.Fields

Dim PMCONT1detail6 As AccpacCOMAPI.AccpacView
Dim PMCONT1detail6Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PM0851", PMCONT1detail6
Set PMCONT1detail6Fields = PMCONT1detail6.Fields

Dim PMCONT1detail7 As AccpacCOMAPI.AccpacView
Dim PMCONT1detail7Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PM0852", PMCONT1detail7
Set PMCONT1detail7Fields = PMCONT1detail7.Fields

Dim PMCONT1detail8 As AccpacCOMAPI.AccpacView
Dim PMCONT1detail8Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "PM0853", PMCONT1detail8
Set PMCONT1detail8Fields = PMCONT1detail8.Fields

PMCONT1header.Compose Array(PMCONT1detail1, PMCONT1detail2, PMCONT1detail3, PMCONT1detail4, PMCONT1detail5)

PMCONT1detail1.Compose Array(PMCONT1header, PMCONT1detail2, PMCONT1detail3, PMCONT1detail4, PMCONT1detail6)

PMCONT1detail2.Compose Array(PMCONT1detail1, PMCONT1header, PMCONT1detail7)

PMCONT1detail3.Compose Array(PMCONT1detail1, PMCONT1header, PMCONT1detail2, PMCONT1detail4, PMCONT1detail8)

PMCONT1detail4.Compose Array(PMCONT1detail1, PMCONT1header, PMCONT1detail2, PMCONT1detail3)

PMCONT1detail5.Compose Array(PMCONT1header)

PMCONT1detail6.Compose Array(PMCONT1detail1)

PMCONT1detail7.Compose Array(PMCONT1detail2)

PMCONT1detail8.Compose Array(PMCONT1detail3)


PMCONT1header.Order = 1

PMCONT1header.Fields("CONTRACT").PutWithoutVerification "MAK120050"

If Not PMCONT1header.Read Then
MsgBox "Error job not found"
Exit Sub
End If
PMCONT1detail4Fields("REVERSE").Value = "1" ' Reverse Resource/Category
temp = PMCONT1detail2.Exists
PMCONT1detail2.RecordCreate 0
temp = PMCONT1detail2.Exists
PMCONT1header.Init
temp = PMCONT1header.Exists
PMCONT1header.Read
temp = PMCONT1header.Exists
PMCONT1detail1Fields("PLINENUM").PutWithoutVerification ("32") ' Line Number
PMCONT1detail1.Read
PMCONT1detail3Fields("TYPE").Value = "2" ' Cost Class
PMCONT1detail3.Browse "(PROJECT=""1001"" AND TYPE=2)", 1
temp = PMCONT1detail4.Exists
PMCONT1detail3Fields("CLINENUM").PutWithoutVerification ("-2147483647") ' Line Number
PMCONT1detail3.Browse "(PROJECT=""1001"" AND TYPE=2)", -1
PMCONT1detail3.Fetch

PMCONT1detail3Fields("CLINENUM").PutWithoutVerification ("2147483647") ' Line Number

PMCONT1detail3.Browse "(PROJECT=""1001"" AND TYPE=2)", 0
PMCONT1detail3.Fetch
temp = PMCONT1detail3.Exists
PMCONT1detail3.RecordClear
temp = PMCONT1detail3.Exists
PMCONT1detail3.RecordCreate 0
temp = PMCONT1detail3.Exists
PMCONT1detail4.Browse "(PROJECT=""1001"" AND RESOURCE="" ""AND TYPE = 2"")", 1
PMCONT1detail4Fields("TYPE").Value = "2" ' Cost Class
temp = PMCONT1detail3.Exists

PMCONT1detail3Fields("RESOURCE").Value = "A1-500/0" ' Miscellaneous Code

PMCONT1detail3Fields("FUNCTION").PutWithoutVerification ("10") ' Function

PMCONT1detail3.Process
temp = PMCONT1detail3.Exists
PMCONT1detail4.Browse "(PROJECT=""1001"" AND RESOURCE=""A1-500/0"" AND TYPE = 2"")", 1
temp = PMCONT1detail3.Exists
PMCONT1detail3.Insert
PMCONT1detail1.Update
PMCONT1detail3Fields("CLINENUM").PutWithoutVerification ("-1") ' Line Number
PMCONT1detail3.Read
temp = PMCONT1detail3.Exists
temp = PMCONT1detail4.Exists
PMCONT1detail4.RecordClear
temp = PMCONT1detail4.Exists
PMCONT1detail4.RecordCreate 0
temp = PMCONT1detail3.Exists

temp = PMCONT1detail4.Exists

PMCONT1detail4Fields("CATEGORY").Value = "PRCHDSKLGT" ' Category

temp = PMCONT1detail4.Exists
PMCONT1detail4.Insert
PMCONT1detail3.Read
PMCONT1detail1.Update
PMCONT1detail2Fields("CLINENUM").PutWithoutVerification ("-2147483647") ' Line Number
PMCONT1detail2.Browse "", -1


PMCONT1detail2Fields("CLINENUM").PutWithoutVerification ("-1") ' Line Number

PMCONT1detail2.Read
PMCONT1detail2.Browse "", -1
PMCONT1detail2.Fetch
PMCONT1detail4Fields("CLINENUM").PutWithoutVerification ("-13") ' Line Number
PMCONT1detail4.Read
temp = PMCONT1detail4.Exists
PMCONT1header.Update


Exit Sub

ACCPACErrorHandler:
Dim lCount As Long
Dim lIndex As Long

If Errors Is Nothing Then
MsgBox Err.Description
Else
lCount = Errors.Count

If lCount = 0 Then
MsgBox Err.Description
Else
For lIndex = 0 To lCount - 1
MsgBox Errors.Item(lIndex)
Next
Errors.Clear
End If
Resume Next

End If
 
One quick suggestion - always change .Order of your view back to 0 before posting.

PMCONT1header.Order = 0
 
thanks... redone the whole program.. now it is working..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top