AxaptaCOMConnector using incorrect Company/DataAreaID

Phil_Walker
Member Posts: 3
Hi All,
Context: I'm looking at integrating our stock-counting system (Microsoft Access/VBA) more closely with Axapta using the AxaptaCOMConnector. The intention is to automate the transfer of results from the stock-counting system into an Axapta table called SynStockTake. This will remove much user intervention to export/import several batches of data.
Setup: I have created an Axapta class called SynStkTkRemote with a method called countLinesAdd intended to be called from Access which will add a record into the Axapta table. To create the standard COM I created a new configuration called 'Connector' with the appropriate application, database and company (DataAreaID) setup. I have tested the AxaptaCOMConnector with the Axapta Class using VB6 and Microsoft Access and VBA - and on the surface seems fine. The VB program creates the COM Objects, Logs onto Axapta, executes Axapta methods, Logs Off Axapta, and finally the objects are destroyed.
Problem: When the VB program launches, the button clicked to execute the CountLinesAdd method works fine ONLY the first time it is used - i.e. the records are added to SynStockTake as expected into the correct company (SYN). There-after the class uses the 'DAT' company instead - i.e. countLinesAdd() adds records to, and getCheckQty() queries the 'DAT' dataAreaID. The only way to make sure the correct company is used again is to completely close the program and re-run it - which will not be feasible in a live environment. The class works fine everytime within Axapta itself.
Attempted Solutions:
Axapta Version: Navision Axapta 3.0 Build #1951.210/514-90 SP2/OP023-19
User Operating System: WinXP
AxaptaCOMConnector version: 1.2
I've googled this problem with no result. Has anybody else experienced this? I would be extremely grateful for any help/suggestions.
Axapta Class:
VB6/VBA Code:
Context: I'm looking at integrating our stock-counting system (Microsoft Access/VBA) more closely with Axapta using the AxaptaCOMConnector. The intention is to automate the transfer of results from the stock-counting system into an Axapta table called SynStockTake. This will remove much user intervention to export/import several batches of data.
Setup: I have created an Axapta class called SynStkTkRemote with a method called countLinesAdd intended to be called from Access which will add a record into the Axapta table. To create the standard COM I created a new configuration called 'Connector' with the appropriate application, database and company (DataAreaID) setup. I have tested the AxaptaCOMConnector with the Axapta Class using VB6 and Microsoft Access and VBA - and on the surface seems fine. The VB program creates the COM Objects, Logs onto Axapta, executes Axapta methods, Logs Off Axapta, and finally the objects are destroyed.
Problem: When the VB program launches, the button clicked to execute the CountLinesAdd method works fine ONLY the first time it is used - i.e. the records are added to SynStockTake as expected into the correct company (SYN). There-after the class uses the 'DAT' company instead - i.e. countLinesAdd() adds records to, and getCheckQty() queries the 'DAT' dataAreaID. The only way to make sure the correct company is used again is to completely close the program and re-run it - which will not be feasible in a live environment. The class works fine everytime within Axapta itself.
Attempted Solutions:
-
1) I've tried to force the Axapta Class to use the 'SYN' company by adding ChangeCompany('SYN') and SynStockTake.company('SYN') with no sucess.
2) It crossed my mind the AxaptaCOMConnector might be picking up the Company from the 'Original (installed configuration)' Axapta configuration so I amended the registry settings accordingly and re-registered the COM Components, again with no sucess.
3) In the AxaptaCOMConnector.Axapta class, the logon() method includes a parameter to specify the configuration used - this makes no difference.
Axapta Version: Navision Axapta 3.0 Build #1951.210/514-90 SP2/OP023-19
User Operating System: WinXP
AxaptaCOMConnector version: 1.2
I've googled this problem with no result. Has anybody else experienced this? I would be extremely grateful for any help/suggestions.
Axapta Class:
public class SynStkTkRemote { SynStockTake SynStockTake; } Static void Main(Args _args) { } void new() { ; ChangeCompany('SYN') SynStockTake.company('SYN'); } private void setCompany() { ; ChangeCompany('SYN') SynStockTake.company('SYN'); } public int countLinesAdd(ItemID _ItemID, WMSLocationID _WMSLocationID, WMSPalletID _WMSPalletID, InventQty _QtyCounted, SynStkCntType _RecordType) { ; this.setCompany(); ttsbegin; SynStockTake.clear(); SynStockTake.initValue(); SynStockTake.ItemId = _ItemID; SynStockTake.WMSLocationId = _WMSLocationID; SynStockTake.WMSPalletID = _WMSPalletID; SynStockTake.QtyCounted = _QtyCounted; SynStockTake.RecordType = _RecordType; SynStockTake.insert(); ttscommit; return 1; // to develop: return 0 if insert failed. } public real getCheckQty() { real checkQty; ; this.setCompany(); SynStockTake.company('SYN'); checkQty = (Select Sum(QtyCounted) From SynStockTake).QtyCounted; return checkQty; }
VB6/VBA Code:
Private Sub cmdAddRecord_Click() Dim Axapta As AxaptaCOMConnector.Axapta Dim axStk As AxaptaCOMConnector.IAxaptaObject Set Axapta = New AxaptaCOMConnector.Axapta Axapta.Logon Set axStk = Axapta.CreateObject("SynStkTkRemote") MsgBox axStk.Call("countLinesAdd", Me.txtItemID.Text, Me.txtLocation.Text, Me.txtStillage.Text, CInt(Me.txtQtyCounted), 1) Axapta.Logoff Set axStk = Nothing Set Axapta = Nothing End Sub Private Sub cmdCheckQty_Click() Dim Axapta As AxaptaCOMConnector.Axapta Dim axStk As AxaptaCOMConnector.IAxaptaObject Set Axapta = New AxaptaCOMConnector.Axapta Axapta.Logon , , , "Connector" Set axStk = Axapta.CreateObject("SynStkTkRemote") MsgBox axStk.Call("getCheckQty") Axapta.Logoff Set axStk = Nothing Set Axapta = Nothing End Sub
0
Comments
-
Hi,
I've had a reply from another forum, the solution is:ChangeCompany("SYN") { // Code Here }
for example, my original getCheckQty() method now becomes...public real getCheckQty() { real checkQty; ; ChangeCompany("SYN") { checkQty = (Select Sum(QtyCounted) From SynStockTake).QtyCounted; } return checkQty; }
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions