Sage MAS 90 and 200 Sage MAS 500 blogs Product Feedback Support Training
Reply
Sage MAS 90 Customer
hyanaga
Posts: 34
Registered: 11-16-2010
0

Sendkeys doesn't appear to work, is there a reference to know which one to use?

I'm using MAS 90 v4.3, trying to use SendKeys to save a Sales Order in a script.  I have External Access turned on for the company. This is my code:

 

Set objShell = CreateObject("WScript.Shell")
objShell.AppActivate("* Sales Order Entry")
objShell.SendKeys "%a"

 

Nothing happens.  I called it from a button on the Lines tab, if the focus is on an empty lines, it tells me that the item code is required.  I called it from a button on the Main panel, it doesn't do anything. 

 

I can use sendkeys with the TAB command and it does tab.  I tried it with parentheses around the "%a". 

 

Am I using the wrong command?  Logic tells me it should be %a to represent the "Alt a" that I use on the keyboard, but I know sometimes it's not that logical.  I've tried several other letters to know avail.

 

Thanks, Hollie

Thanks!
Hollie
Contributor
Pappy
Posts: 32
Registered: 11-21-2008
0

Re: Sendkeys doesn't appear to work, is there a reference to know which one to use?

[ Edited ]

Good Afternoon Hollie,

 

The following is a snippet of a script that wrote that checks for Duplicate PO's in Open Orders and recent AR Invoices.  I replaced the "Quick Print" & "Accept" buttons and the script determines what to do depending upon which one was clicked.

... It just caught my eye ... You used a lower-case "a" ... Use the same case as the alt-key.

		Select Case MAS_SCR_OBJ
			CASE "BT_LINK_3"
				'MsgBox "Select Case (BT_Link_3) sendkey"
				sh.sendkeys "%A"
			CASE "BT_LINK_4"
				sh.sendkeys "%K"
			CASE "BT_LINK_5"
				sh.sendkeys "%A"
			CASE "BT_LINK_6"
				sh.sendkeys "%K"
		End Select

 Buttons 3 & 4 are for the Wide-View, and buttons 5 & 6 for the narrow view (just to explain why there are four options for two buttons).

Sage MAS 90 Customer
hyanaga
Posts: 34
Registered: 11-16-2010
0

Re: Sendkeys doesn't appear to work, is there a reference to know which one to use?

Thanks for your reply, I actually did see your post and was impressed with the code.  I have tried using uppercase A, I forgot to mention that, and it still does not work.  I thought it might be lowercase because when I do the keyboard keys, I don't have to use Shift with the Alt A, so I thought it might work.

 

I'm still stumped.  I'll try the %K to see if Quick Print will work. 

Thanks!
Hollie
Sage MAS 90 Customer
hyanaga
Posts: 34
Registered: 11-16-2010
0

Re: Sendkeys doesn't appear to work, is there a reference to know which one to use?

Interesting.  %K didn't work either, so I got frustrated and just kept clicking the button over and over, and on about the 20th click, it worked.  For %A too.

 

Anybody have any idea why this might not work on the first click?

 

Thanks!
Hollie
Sage MAS 90 Customer
hyanaga
Posts: 34
Registered: 11-16-2010
0

Re: Sendkeys doesn't appear to work, is there a reference to know which one to use?

I removed all the code that I had in my script following the SendKeys, and now it works.  Is there a problem running code after the SendKeys?

 

I'm trying to save the order, then recall it on the window for the user.  I need to use SendKeys to simulate the user entering the Sales Order number.  I read in another post that it's possible to do this in v4.3.  If anyone knows how, I'd appreciate the help.

 

This is my code:

 

 

OrderNumber = SO_SalesOrder_bus_SalesOrderNo
 
Set objShell = CreateObject("WScript.Shell")
objShell.AppActivate("* Sales Order Entry")
objShell.SendKeys ("%A")

SO_SalesOrder_bus_SalesOrderNo = OrderNumber
objShell.SendKeys("{ENTER}")

 

 

 

I don't think I can set the SalesOrderNo field this way because it says it's display only.  Does anyone know how I should do it correctly?

 

Thanks, Hollie

Thanks!
Hollie
Sage MAS 90 Customer
hyanaga
Posts: 34
Registered: 11-16-2010
0

Re: Sendkeys doesn't appear to work, is there a reference to know which one to use?

I know I am missing something here.  When I put any code after the SendKeys, the SendKeys does not run.  I thought I'd post my full code and purpose in case someone has something similar and can help.

 

My client needs to calculate a fee on a sales order based on the list price of the line items.  Since they are in v4.3 and can't use the Advanced Scripting available in later versions, this is challenging.  I've read in other posts that the only way to do this is to force a save of the order (hence the SendKeys), then retrieve the order and calculate based on the lines. 

 

Here is my code and thank you in advance to anyone who is more adept at this. 

 

Dim oScript
Dim oSS
Dim oSOOrder
Dim fee, OrdQty, Retail, OrderNumber, totalfee

Dim objShell, WshShell
 
If SO_SalesOrder_bus_UDF_BILL_DR = "Y" Then

SO_SalesOrder_bus_UDF_FEE_TOTAL = 0
OrderNumber = SO_SalesOrder_bus_SalesOrderNo

Set objShell = CreateObject("WScript.Shell")
objShell.AppActivate("* Sales Order Entry")
objShell.SendKeys "%A"
'Set ObjShell = nothing

' Create the ProvideX COM Object
Set oScript = CreateObject ("ProvideX.Script")

PathHome = "C:\Sage Software\MAS 90\Version43\MAS90"
oScript.Init(PathHome)

'NewObject method creates a new MAS 90 Session object and returns the objects reference in oSS
Set oSS = oScript.NewObject("SY_Session")

'Set login values
  retVal = oSS.nSetUser("hollie","hollie")
  retVal = oSS.nSetCompany(MAS_SCR_CMP)
  retVal = oSS.nSetDate("S/O",MAS_SCR_DTE)
  retVal = oSS.nSetModule("S/O")
  retVal = oSS.nSetProgram(oSS.nLookupTask("SO_SalesOrder_ui"))

Set oSOOrder = oScript.NewObject("SO_SalesOrder_bus", oSS)

retVal = oSOOrder.nSetKey(OrderNumber)

totalfee = 0 
retVal = oSOOrder.nSetValue("UDF_FEE_TOTAL",totalfee)

retVal = oSOOrder.oLines.nMoveFirst()
Do 
    retval = oSOOrder.oLines.nGetValue("UDF_RETAIL_PRICE",Retail)
    retval = oSOOrder.oLines.nGetValue("QuantityOrdered",OrdQty)
    fee = Retail * OrdQty * .10
    totalfee = totalfee + fee
    oSOOrder.oLines.nmovenext()
Loop Until Cbool(oSOOrder.oLines.nEOF)

'retVal = oSOOrder.nSetValue("UDF_FEE_TOTAL",totalfee)
SO_SalesOrder_bus_UDF_FEE_TOTAL = totalfee

retVal = oSOOrder.DropObject()
oSOOrder = 0
Set ObjShell = nothing

else

Msgbox "Bill Doctor is not indicated, no fees apply."

End If

 I'm struggling with 2 main issues:  SendKeys "%A" does not work where it is in the code, and how to bring the order back up on the screen once I get issue one to work.

 

Thanks, Holllie

Thanks!
Hollie