Can't Move Focus Problem

T

tkosel

I hope this isn't too long winded!

I have a simple little form with 4 controls on it. Three of the controls
have Got Focus Events as illustrated below.
A scanner is attached to Com2 which is being controlled(?) by a MSComm
active X control.(Named "NewMatCom) Tab order is PartNumber, LotNumber,
ClockNumber, NextControl

When I scan, PartNumber gets populated, focus moves to next control,
LotNumber.
I scan again, LotNumber gets populated, focus moves to the next control,
ClockNumber
I scan again, ClockNumber get populated, however now Access gives a run time
error '2110' and says it can't move the
focus to the control ClockNumber. When I debug, it is breaking on the
'Me.ClockNumber.SetFocus' statement in the LotNumber
procedure. When I step through that, it says it can't move the focus to the
LotNumber control. When I debug that, it is
breaking on the 'Me.LotNumber.SetFocus' statement in the PartNumber
procedure. When I step through that, it finishes but
locks up. Control Break Takes me back to the form, the fields are all filled
in, the focus is on the lot number field.

The scanned input string is ended by a Carriage Return. (Programmed into the
Scanner as "Enter" key.)

Any ideas on what is wrong?

=====================================================

Private Sub PartNumber_GotFocus()

Dim V_IncomingDataStream
If Me.NewMatCom.PortOpen = False Then 'Open the port
Me.NewMatCom.PortOpen = True
End If
Do
If Me.NewMatCom.PortOpen = False Then
Exit Do
End If
V_IncomingDataStream = V_IncomingDataStream &_
Me.NewMatCom.Input 'Read the data
Loop Until InStr(V_IncomingDataStream, vbCr) 'Decide if it is complete
If Me.NewMatCom.PortOpen = True Then 'Close the port
Me.NewMatCom.PortOpen = False
End If
Me.PartNumber.Locked = False
Me.PartNumber = V_IncomingDataStream
Me.PartNumber.Locked = True
Me.Repaint

Done:

Me.LotNumber.SetFocus

End Sub
=====================================================

Private Sub LotNumber_GotFocus()

Dim V_IncomingDataStream
If Me.NewMatCom.PortOpen = False Then 'Open the port
Me.NewMatCom.PortOpen = True
End If
Do
If Me.NewMatCom.PortOpen = False Then
Exit Do
End If
V_IncomingDataStream = V_IncomingDataStream &_
Me.NewMatCom.Input 'Read the data
Loop Until InStr(V_IncomingDataStream, vbCr) 'Decide if it is complete
If Me.NewMatCom.PortOpen = True Then 'Close the port
Me.NewMatCom.PortOpen = False
End If
Me.LotNumber.Locked = False
Me.LotNumber = V_IncomingDataStream
Me.LotNumber.Locked = True

Done:

Me.ClockNumber.SetFocus

End Sub
====================================================

Private Sub ClockNumber_GotFocus()

Dim V_IncomingDataStream
If Me.NewMatCom.PortOpen = False Then 'Open the port
Me.NewMatCom.PortOpen = True
End If
Do
If Me.NewMatCom.PortOpen = False Then
Exit Do
End If
V_IncomingDataStream = V_IncomingDataStream &_
Me.NewMatCom.Input 'Read the data
Loop Until InStr(V_IncomingDataStream, vbCr) 'Decide if it is complete
If Me.NewMatCom.PortOpen = True Then 'Close the port
Me.NewMatCom.PortOpen = False
End If
Me.ClockNumber.Locked = False
Me.ClockNumber = V_IncomingDataStream
Me.ClockNumber.Locked = True

Done:

Me.NextControl.SetFocus

End Sub
 
K

Ken Snell

Sounds like a timing issue to me. Why use all those GotFocus events to run
this code? It appears that you're sequentially reading data in the code, so
why not just have one event procedure that combines all the read and
setfocus steps in it, and eliminate the whole issue?

In other words, use a button to initiate the running of code that does this:

Read data for PartNumber.
Write data into PartNumber.
Read data for LotNumber.
Write data into LotNumber.
Read data for ClockNumber.
Write data into ClockNumber.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top