• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 610
  • Last Modified:

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

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

Open in new window

0
colinasad
Asked:
colinasad
  • 4
  • 4
2 Solutions
 
colinasadAuthor Commented:
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.
0
 
jrinlaCommented:
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
0
 
colinasadAuthor Commented:
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.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
jrinlaCommented:
How did you open the port in the first place? I can't access PortOpen.
0
 
colinasadAuthor Commented:
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.
0
 
jrinlaCommented:
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
0
 
jrinlaCommented:
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.
0
 
colinasadAuthor Commented:
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.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now