Link to home
Start Free TrialLog in
Avatar of kdwood
kdwood

asked on

MSComm Control won't work with code called from a module.

Greetings,

I have an inventory control application that triggers the opening of mechanical drawers via the serial port.  Using MSComm works great, as long as the code below is embedded as a subroutine behind the calling form.  However, I would like to put this code into a module function, as it will be called from multiple locations within the application.

When I try the code below in a module, I get the following error:   "Run-Time Error 424 . . .  Object Required"

Any help would be appreciated.

Thank you in advance,

Keith

--------------------------------
CODE
--------------------------------

Function OpenDrawer()
   
    myDrawer = Forms!frmSelectQty.txtDrawer
   
' Initialize Com Port Parameters

    MSComm1.CommPort = 1
    MSComm1.Settings = "9600,N,8,1"
    MSComm1.InputLen = 1
    MSComm1.PortOpen = True
    MSComm1.HandShaking = 2

' Check to see if Drawer is already open

    If MSComm1.CTSHolding Then
       GoTo OpenMe
    Else
       MsgBox "The Drawer is Currently Open.  You must close the open drawer to continue.", vbCritical
       Exit Function
    End If
   
' Send String to Drawer to Open

OpenMe:
 
    myTrigger = Chr$(myDrawer)
    MSComm1.Output = myTrigger
    MSComm1.PortOpen = False

End Function
Avatar of arcross
arcross
Flag of United Kingdom of Great Britain and Northern Ireland image

in the module...

Public Sub TEst()

Dim MyComm as MsCOmm

' Here refrence the form where you have dragged the control
Set MyComm = Forms.YourFormName.MsCommName.Object
...


Álvaro


Function OpenDrawer()

Dim MyComm as MSComm
Set MyComm = Forms!frmSelectQty.MsComm1.Object    ' Asuuming in this form you have the MsCOmm contrl
   

 myDrawer = Forms!frmSelectQty.txtDrawer
   
' Initialize Com Port Parameters

    MSComm1.CommPort = 1
    MSComm1.Settings = "9600,N,8,1"
    MSComm1.InputLen = 1
    MSComm1.PortOpen = True
    MSComm1.HandShaking = 2
ASKER CERTIFIED SOLUTION
Avatar of arcross
arcross
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kdwood
kdwood

ASKER

arcross,

Your suggestion worked perfectly.   Thank you for the quick response.


Regards,

Keith