Solved

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

Posted on 2004-04-16
4
543 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 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

808 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