SetFocus to Text Box Not Working

DavidWE

Registered User.
Local time
Today, 14:42
Joined
Aug 4, 2006
Messages
76
I am using Access 2000 and read somewhere that my problem might be a quirk.

I need to have the focus return to the textbox, txtBar, in the code below. The focus always goes to the next field in the tab order of the form. I've changed the tab order and it always goes to the next command button or text field in the tab order. It is currently tabbing to txtLastScan. With the below code, I have tried setting the text change and text update events for txtLastScan to txtBar.SetFocus without any luck. I have an almost identical routine in another Access db that does not have this problem. In that db, txtBar.Text = " " is all it takes to set the focus back to txtBar. I've tried with and without txtBar.SetFocus on the current db and get the same results.

Thanks for any suggestions.

Code:
Private Sub txtBar_Change()
    If Len(txtBar.Text) = 20 Then
       LogCount = LogCount + 1      
       With rst
              .AddNew
              .Fields("BarCode") = txtBar.Text
              .Fields("ScanDate") = txtScanDate.Value
              .Fields("ScanNo") = ScanNo
              .Fields("Quantity") = 1
              .Update
          End With
      
          txtLastScan.Value = txtBar.Text
          txtBar.Text = " "
          txtBar.SetFocus
    End If
End Sub
 
I need to add to my above question. The txtBar_Change event is executed when a barcode of 20 characters is scanned. I do not have a problem with SetFocus when I type the barcode into the txtBar. It is only when scanning. I just noticed that the barcodes for the db I mentioned above that does work, have "*" before and after the chararacters in the barcode. The barcodes I'm testing for the new db do not. So the problem has to do with the format of the barcode. I will have to figure that out.
 
I think you're right, barcode scanners are usually set up to transmit the enter command after the text. You should be able to reconfigure the barcode scanner, this is usually done with a booklet that comes with the barcode scanner, The booklet should have a set of bar codes In it which you scan to configure the scanner.
 
I've not used a barcode scanner in Access before and I'm sure that Uncle Giz has got you on the right path, but resetting the textbox is calling the code multiple times and not getting to the SetFocus line eventually. Therefore,
Code:
Private Sub txtBar_Change()
    If Len(txtBar.Text) = 20 Then
       LogCount = LogCount + 1      
       With rst
              .AddNew
              .Fields("BarCode") = txtBar.Text
              .Fields("ScanDate") = txtScanDate.Value
              .Fields("ScanNo") = ScanNo
              .Fields("Quantity") = 1
              .Update
          End With
 
          txtLastScan.Value = txtBar.Text
[COLOR=red]         txtbar.OnChange = ""[/COLOR]
          txtBar.Text = " "
[COLOR=red]         txtbar.OnChange = "[Event Procedure]"[/COLOR]
          txtBar.SetFocus
    End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom