By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,089 Members | 1,017 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,089 IT Pros & Developers. It's quick & easy.

Unable to set focus on a text box

P: n/a
This is a re-post of a problem I have been struggling with for some time
now.
I'm sure I'm doing something silly!

I have a data entry form with text boxes bound to a query.

The user can enter data into the text boxes using a barcode scanner. The
data is checked against an underlying table to see if the barcode is valid.
If the user scans the correct data everything is fine.
If the user scans data that is not contained in the underlying table I want
to discard the data and re-scan.
I can use a mouse to select the faulty data in the text box and re-scan with
no problems, but the user will only have a barcode scanner and no mouse.
When I try to move the focus to the text box I get an error "You must save
the field before you execute the SetFocus method"
Not only do I not want to save it, but I can't seem to do anything with it.

Undo commands have no effect, nor does making the text boxes unbound

I can close the form and re-open, but that forces the operator to log in
again

A copy of the relevent code is :

Set rs = db.OpenRecordset("TblCustomer")

rs.Index = "AccountNum"
rs.Seek "=", Forms!FrmMov.CustNum.Text
If rs.NoMatch Then
MsgBox ("The barcode scanned is not recognised as a Customer " & Chr(13) &
Chr(13) & _
"Scan any barcode to continue")

Forms!FrmMov.CustNum.SetFocus 'Error occures here
Forms!FrmMov.CustNum.Text = ""

Exit Sub

Any help would be appreciated

Regards
PeterW


Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
PeterW wrote:
I can use a mouse to select the faulty data in the text box and re-scan with
no problems, but the user will only have a barcode scanner and no mouse.
When I try to move the focus to the text box I get an error "You must save
the field before you execute the SetFocus method"
Not only do I not want to save it, but I can't seem to do anything with it.


The thing to do here is determine if the action of the scanner is firing
the event in which you have the code versus using the mouse.

I use Keyboard wedges and depending on the function of the user, the
scanner may be programmed to tab out of a field after scanning or not.

How your scanner is configured may have something to do with your issue.
The keyboard wedges we use come with a book full of barcodes to scan
to obtain various types of behaviour.

Another big question is, where do you have this code? You don't say,
but by use of the .text property of CustNum, I'm assuming this is in the
before update.

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #2

P: n/a

"PeterW" <pw****@btinternet.com> bl
news:ct**********@hercules.btinternet.com g...
This is a re-post of a problem I have been struggling with for some time
now.
I'm sure I'm doing something silly!

I have a data entry form with text boxes bound to a query.

The user can enter data into the text boxes using a barcode scanner. The
data is checked against an underlying table to see if the barcode is valid. If the user scans the correct data everything is fine.
If the user scans data that is not contained in the underlying table I want to discard the data and re-scan.
I can use a mouse to select the faulty data in the text box and re-scan with no problems, but the user will only have a barcode scanner and no mouse.
When I try to move the focus to the text box I get an error "You must save
the field before you execute the SetFocus method"
Not only do I not want to save it, but I can't seem to do anything with it.
Undo commands have no effect, nor does making the text boxes unbound

I can close the form and re-open, but that forces the operator to log in
again

A copy of the relevent code is :

Set rs = db.OpenRecordset("TblCustomer")

rs.Index = "AccountNum"
rs.Seek "=", Forms!FrmMov.CustNum.Text
If rs.NoMatch Then
MsgBox ("The barcode scanned is not recognised as a Customer " & Chr(13) &
Chr(13) & _
"Scan any barcode to continue")

Forms!FrmMov.CustNum.SetFocus 'Error occures here
Forms!FrmMov.CustNum.Text = ""

Exit Sub

Any help would be appreciated

Regards
PeterW

put above code into CustNum_exit as below:

Private Sub CustNum_Exit(Cancel As Integer)

Set rs = db.OpenRecordset("TblCustomer")

rs.Index = "AccountNum"
rs.Seek "=", Forms!FrmMov.CustNum.Text
If rs.NoMatch Then
MsgBox ("The barcode scanned is not recognised as a Customer " & Chr(13) &
Chr(13) & _
"Scan any barcode to continue")

'Forms!FrmMov.CustNum.SetFocus 'Error occures here

Forms!FrmMov.CustNum.Text = ""
DoCmd.CancelEvent
End If

End Sub
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.