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

AR / AP Batches in 55 1

Status
Not open for further replies.

Bluejay07

Programmer
Mar 9, 2007
780
CA
Hello,

I am trying to create a batch in AP. I have some code that works great in AR but trying something similar in AP gives me an error:

438; Object doesn't support this property or method.

Here is the code for AP:
Code:
Dim APBTA As AccpacCOMAPI.AccpacView
   
On Error GoTo ERR_Handler
   
cdDBLink.OpenView "AP0030", APBTA
With APBTA
   .Fields("PAYMTYPE").PutWithoutVerification ("PY")     '// Batch Selector.
   .Fields("CNTBTCH").PutWithoutVerification ("0")       '// Batch Number      
   .Init
      
   .Fields("BATCHDESC").Value = GetSetting(REG_ROOT, "SAInfo", "APBatchDesc", "") & " " & FormatDateTime(Date, vbShortDate)
   .Fields("DATEBTCH").Value = Date
   .Fields("IDBANK").Value = GetSetting(REG_ROOT, "SAInfo", "APBankCode", "")
   .Fields("BATCHTYPE").Value = 2      '// 2 = Imported.
   .Update

End With

I have tried several variations and constantly get the same error message. I have also tried recording a macro and still the same error.

Looking through the threads, I came across the following:
which ettienne replied with something similar to my macro.

Can anyone help me to overcome this problem?

Thanks.
 
Hello ettienne,

With the code as it is above, the code fails on the .init line.
 
Try replace .Init with .RecordCreate 1
Other things to check are:
Is your dblink read-write
Does the user have rights to create a batch (if not logged in as ADMIN)
 
I changed to .RecordCreate 1 and exact same error as soon as it tries to execute it.

The dblink should be read-write as this code works in AR.
As for accpac, I am logged in as ADMIN so rights are not an issue in this case.
 
I overlooked the obvious, you are only opening APBTA. You need to open the detail views and compose them as well before you can create an AP payment batch, it's just one of those things. If you have an error handler you will get an error saying something about you need to open and compose the views.
 
With the additions of the opening and composing the views, I still get an error.

I have also replaced my error handler with that of the macro and get another error.

Code:
Dim APBTA As AccpacCOMAPI.AccpacView
Dim APTCR As AccpacCOMAPI.AccpacView
Dim APTCP As AccpacCOMAPI.AccpacView
Dim APTCU As AccpacCOMAPI.AccpacView
Dim APTCN As AccpacCOMAPI.AccpacView
Dim APPOOP As AccpacCOMAPI.AccpacView
Dim APTCRO As AccpacCOMAPI.AccpacView
Dim APTCC As AccpacCOMAPI.AccpacView

On Error GoTo ERR_Handler

'// Set the views.
cdDBLink.OpenView "AP0030", APBTA
cdDBLink.OpenView "AP0031", APTCR
cdDBLink.OpenView "AP0033", APTCP
cdDBLink.OpenView "AP0034", APTCU
cdDBLink.OpenView "AP0032", APTCN
cdDBLink.OpenView "AP0048", APPOOP
cdDBLink.OpenView "AP0170", APTCC
cdDBLink.OpenView "AP0406", APTCRO
   
With APBTA
   .Fields("PAYMTYPE").PutWithoutVerification ("PY")     '// Batch Selector.
   .Fields("CNTBTCH").PutWithoutVerification ("0")       '// Batch Number
   .RecordCreate 1

   '.Init
      
   .Fields("BATCHDESC").Value = GetSetting(REG_ROOT, "SAInfo", "APBatchDesc", "")
   .Fields("DATEBTCH").Value = Date
   .Fields("IDBANK").Value = GetSetting(REG_ROOT, "SAInfo", "APBankCode", "")
   .Fields("BATCHTYPE").Value = 2      '// 2 = Imported.
   .Update
      
End With
Set APBTA = Nothing
Exit Sub
   
ERR_Handler:
  Dim lCount As Long
  Dim lIndex As Long

  If Errors Is Nothing Then
       MsgBox Err.Description
  Else
      [COLOR=red]Errors.count shows 'The "Session" object was not opened - yet I can access session info (eg. .companyname) in the immediate window[/color]
      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
 
I thank you for your time, ettienne.

I am using VB6
 
Ah that makes a difference. In VBA the session object already exists, in VB you need to declare it and initialize it, so the session object does not exist.
 
sorry for the confusion.

When my program starts, I am referencing the signon manager using the following code:

Code:
'// Set the Sage Accpac objects.
Set cdSignonManager = New AccpacSignonManager.AccpacSignonMgr
Set cdSess = New AccpacCOMAPI.AccpacSession
   
'// Open the Sage Accpac Session.
cdSess.Init "", "AS", "AS1000", "55A"
cdSignonManager.Signon cdSess
If cdSess.IsOpened Then
   
  cdSess.EnforceAppVersion = False
         
  '// Set the DBLink object for the views.
  Set cdDBLink = cdSess.OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE)
      
  '// Set up the company object.
  Set CSCOMPANY = cdDBLink.GetCompany
      
  Open_SAConnections = True
      
End If

This still doesn't explain why everything works in AR but I'm having so many problems in AP. The tables are practically identical.
 
I see, you do have a session then.
Where do you compose your AP views?
 
The views are all composed in the procedure that uses them. I then set the views to nothing and move to the next section.

In this case, if the transaction is a receipt then I call the procedure to create an AR batch, or if its a payment then AP batch is created.

Further in the program, the ability exists to append to an existing batch(not an issue right now), but I can't seem to create the initial batch.

I have also completely shut down my computer and restarted in case of a potential conflict occuring in memory.
 
In your code snippet you declare the views and open them, but I do not see where you compose them.
Go back to basics: record a macro when you create an AP payment batch and use the generated code (after cleaning up the noise generated) to get it working in VBA first, then move it over to VB.
 
When I was copying the code and opening the views, I did forget to copy the code to compose the views.

By doing so, everything seemed to work after a basic test. I will be testing further next week.

I thank you so much for your help you have provided.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top