Question

I can't seem to get MSCOMM to work with a serial barcode scanner in an Access 2007 Form

Asked by: colinasad

I am developing an Access 2007 "project" (.adp) as a front-end to a SQL Server 2005 Express database.

Earlier today I managed to download and register MSCOMM32.OCX and now appear to be able to add an MSCOMM control to an Access Form.
However, I have not been able to see any input coming in from a barcode scanner attached to my COM1: serial port. When I move over to an old DOS application on the same laptop, the scanner input arrives OK, so I am fairly certain that communication with the computer is OK.

I have attached the code I am using to initialise the MSComm0 control in my "Form_Load" procedure and it reports "No error".

I have also attached what I do in my "MSComm0_OnComm" procedure and although I have many "tracer" MsgBox messages in there, I have only once had one displayed.

After "reading" the MSComm0 input buffer, how is that buffer "emptied"?
Also, in my Form's "Design View", the MSComm0 control's properties do not list many items under the "Events" tab but all the items I have seen on the internet mention the "OnComm" event, which I have produced a VBA procedure for.

Can anyone suggest how I check that MSCOMM is acrually "working" for me and can anyone explain why I don't seem to be getting any data coming through?

Many thanks.

Private Sub Form_Load()
   With Me
       With .MSComm0
            .CommPort = 1
            .Break = False
            .DTREnable = True
            .EOFEnable = False
            .Handshaking = comNone
            .InBufferCount = 0
            .InBufferSize = 1024
            .InputLen = 1024
            .InputMode = comInputModeText
            .NullDiscard = False
            .OutBufferCount = 0
            .OutBufferSize = 1024
            .ParityReplace = Chr(0)
            .RThreshold = 1
            .SThreshold = 0
            .Settings = "9600,N,8,1"
        End With
    
        .MSComm0.PortOpen = True
        
        If Err.Number = 0 Then
            MsgBox "No error after establishing COM port"
        Else
            MsgBox "PROBLEM - error after establishing COM port"
        End If
        
    End With
End Sub ' Form_Load
 
 
Private Sub MSComm0_OnComm()
    Dim strInputString As String
    Dim strChar As String
    
    MsgBox "We are in MSComm0_OnComm"
    With Me.MSComm0
        If .CommEvent = comEvReceive Then
            strInputString = ""
            While .InBufferCount > 0
                strChar = .Input
                MsgBox "Barcod input char : " & strChar
                    
                If strChar = Chr$(13) Then
                    If Not genAllBlanks(Nz(strInputString, "")) Then
                        .cmbStockCode = strInputString
                        MsgBox "Barcode input string : " & strInputString
                    End If
                    strInputString = ""
                Else
                    strInputString = strInputString & strChar
                End If
            Wend
            
        End If
    
    End With
End Sub ' MSComm0_OnComm

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-05-01 at 09:20:56ID24372998
Tags

Microsoft Access 2007

Topics

VB Controls

,

Access Coding/Macros

,

Access Forms

Participating Experts
1
Points
500
Comments
8

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Barcode Scanner???
    I need to incorporate a barcode scanner into a vb app. Anyone have suggestions for a serial/USB slot card scanner for cheap. I don't like wedges because the program may not be on the specific control at the time of swipe. I want to be able to trap the event and the values ...
  2. barcode scanners
    i work with barcode scanners: how can i know when the string came from the barcode and when the string came from the keyboard? i have 10 TEdits on my form and i want to set focus just on one of them when the string came from the barcode. can u tell me what i need to do? than...
  3. Barcode scanner
    I'm looking to buy a barcode scanner with software to use at work. Basically, we are a college and we have music equipment we book out to students (guitars, leads etc). I want to be able to supply each student with a booking card so that they can book out equipment and all I...
  4. barcode scanners
    Hi i'm looking for a barcode scanner that can work on my USB (preferred) or Com1 port on my PC. I want to use it to write my own software on. Only problem is where can i find a cheap barcode scanner that can do the trick?! Anyone any experiance with this ?
  5. Barcode Scanners
    To anyone with expert knowledge and experience on barcode scanners. Are there any such scanners in the market that could work like a handheld scanner as well? I'm trying to have the barcode scanner scan normal characters and have it sent to the computer as an image for furth...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: colinasadPosted on 2009-05-01 at 09:38:34ID: 24281097

Amazing,
after struggling with this all afternoon, composing my question to EE forced me to actually THINK!
I had copied my "initialising" settings from a web article which gave blow-by-blow reasons for each setting and they all seemed plausible.
I have just realised my "handshaking" is really "DTR/CTS". When I changed my code to ".Handshaking = comRTS" - all my scanned barcodes have appeared.

However, can someone still explain why I don't seem to be getting many "events" listed in my control's properties and how my input buffer is being emptied? Although I am reading the content OK, I am unsure how that clears it from the buffer.

Many thanks.

 

by: jrinlaPosted on 2009-05-13 at 03:59:30ID: 24373309

colinasad,

I have been trying to do this for quite sometime. How did you get the mscomm control to work properly in Access 2007?  I registered the mscomm32.ocx control using the macro RegisterActiveXControls. I placed the little telephone looking control onto my form.  But when I go to the Code View and type in MSComm0. I see all the generic properties instead of the mscomm properties you mentioned above (CommEvent, PortOpen, CommPort, etc...).


I thought I remembered there being a great walk through somewhere on the web, but I can't find it.  Any clue what I did wrong?

Thanks,
Josh

 

by: colinasadPosted on 2009-05-14 at 00:27:46ID: 24382372

Hi Josh,
I'm a relative newbie to Access and VBA but have been converting a client's old (25 years) DOS application for the past year. So I'm no expert.
I gained my knowledge on this last week by Googling "Access +"barcode scanner"" and trawling through the various sites that came up. Here is the page where I got my "Form_Load" instructions from :

http://www.users.on.net/~cit/html/visual_basic_mscomm_control.html

Other sites mentioned "Events" such as "OnComm" and although these were not listed in my control's "Events" properties list, I was able to create a VBA procedure behined the scenes called "Private Sub MSComm0_OnComm()" which launched when data came in from the scanner.

Hope this helps.
Colin.

 

by: jrinlaPosted on 2009-05-14 at 00:42:28ID: 24382435

How did you open the port in the first place? I can't access PortOpen.

 

by: colinasadPosted on 2009-05-14 at 01:08:53ID: 24382564

It seems to work for me just as I have laid out my "Form_Load" code in my first message. I have an additional couple of lines that I didn't include in my original question :

        .MSComm0.PortOpen = True
       
        If Err.Number = 0 Then
            ' Dont bother with the message if OK
            ' MsgBox "COM port is open for scanner."
        Else
            MsgBox "PROBLEM - error opening COM port for scanner."
        End If

Again I would have picked this up from some web-site last week. I used it to test whether the port was being successfully opened, then commented out the "OK" message so that the operator is only informed if there is a problem.

In my form's "Form_Close" procedure, I close the serial port by doing the following :
 
         ' Close the barcode scanner port
         If Me.MSComm0.PortOpen Then Me.MSComm0.PortOpen = False
     

Regards. Colin.

 

by: jrinlaPosted on 2009-05-14 at 01:12:57ID: 24382587

I must be loading the mscomm control incorrectly.  I can't get it to allow me to use access any of those properties.

Do you have a link to where it showed you how to import that control? I used the RegisterActiveXControls macro to add in mscomm32.ocx.  

Thanks,
Josh

 

by: jrinlaPosted on 2009-05-14 at 01:29:31ID: 24382666

I am familiar with the mscomm control.  The input buffer is emptied on reads.  The property is .Input.  

myString = MSComm0.Input  

Will return and empty the input buffer.  The Input Buffer can be configured in the Custom properties under InBufferSize, RThreshold, InputLen.  If you google some of those properties you find how to use them.

There is also a property that controls whether it returns strings or bytes.  Bytes can be of use if you are send binary data.


Now if only I could get the thing to work!  I'm sticking to VB6 for now.

 

by: colinasadPosted on 2009-05-14 at 01:43:44ID: 24382737

What I did was the following :

Downloaded "MSCOMM32.OCX" and saved it in "C:\Windows\System32\".

Then I ran "regsvr32 c:\windows\system32\mscomm32.ocx". I seem to remember this being reported as "successful".

Back in my Access 2007 project, in the VBA Editor program I used "Tools - References" and ticked the "Microsoft Comm Control 6.0" box.

After doing all that I was able to add an "Active X Control" of the type "Microsoft Communications Control, version 6.0" into my Access form. To be honest, I had not tried doing this previously so I don't know whether it only worked because of the previous steps.

That gave me the "telephone" icon control that you have also described. I don't think I ran the "RegisterActiveXControls" macro you mentioned, but I would have thought it was doing the same sort of thing, otherwise you wouldn't have got your control.

This morning I have noticed I have another file in my "C:\Windows\System32\" folder, called "MSCOMCTL.OCX" with a much earlier date stamp. I have no idea where that came from and perhaps it was there before I downloaded my "MSCOMM32.OCX".

I'm sorry I can't give you any sort of expert insight into what I was doing, or suggest alternatives. I just followed suggestions from the web and they seemed to work for me.

Regards. Colin.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...