Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-04-16
4
Medium Priority
?
553 Views
Last Modified: 2008-03-03
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
0
Comment
Question by:kdwood
  • 3
4 Comments
 
LVL 8

Expert Comment

by:arcross
ID: 10841748
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


0
 
LVL 8

Expert Comment

by:arcross
ID: 10841802
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
0
 
LVL 8

Accepted Solution

by:
arcross earned 1000 total points
ID: 10841809
Then, substitute

MyComm.CommPort = 1
    MYComm.Settings = "9600,N,8,1"
    MyComm.InputLen = 1
    MyComm.PortOpen = True
    MyComm.HandShaking = 2
0
 
LVL 10

Author Comment

by:kdwood
ID: 10842221
arcross,

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


Regards,

Keith
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question