Solved

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

Posted on 2004-04-16
4
532 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
arcross,

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


Regards,

Keith
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now