Solved

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

Posted on 2004-04-16
4
546 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 250 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

739 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