473,396 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do I make a field set focus after each entry?

269 256MB
Ok, I can officially say I'm in a tight. I'm scheduled to have a baby---day after tomorrow, and I've just found a problem in my database that needs fixing in about 5 work hours. :-O

A while back Bytes experts helped me design a form that was designed for a handheld scanner which would take a 5 digit customer number and then accept a 3 or 4 digit box number right after it. The scanner automatically puts an [ENTER] key after every scan. So if you were doing it manually (as we are at this time, while waiting on our scanner), you would enter 11111, [enter], 136, [enter], 22222, [enter], 145, [enter]. All of this goes into one field and you never have to touch the mouse. Well that's how it WAS. Perfect.

Well genius over here (yes, me) decided I needed to show two additional fields on the form. And I added them. And now I've realized I can no longer do the long series of keystrokes; instead I have to take the mouse and click in the field each time before I can type. This is a hassle...but the bottom line is when we get the scanner, IT WON'T WORK!

I think I may know where I went wrong, but I don't know how to fix it. I noticed in my old (working) DB, the record source on the form is empty. Everything is apparently controlled by the code behind it. The only fields initially shown were the ones being updated, and the code updated it, so it all makes sense. However I wanted to show two additional fields that were not being updated, they just show information. So in my record source I added the tblBOX and put the two fields in it, and then showed them on my form. So now my new (unworking) DB has
Expand|Select|Wrap|Line Numbers
  1. SELECT tblBOX.DATE_BOX_RETURN, tblBOX.ORDER_NUM
in the record source. That is the only difference I can find between the two DBs.

Here is the code running both forms--and it still works great except I've lost the focus!
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Option Compare Database
  3.  
  4. Public strLastScan As String
  5. Public db As DAO.Database
  6.  
  7. Private Sub Form_Open(Cancel As Integer)
  8.     Set db = CurrentDb
  9. End Sub
  10.  
  11. Private Sub txtScanCapture_AfterUpdate()
  12.     Dim strSQL As String
  13.  
  14.     Select Case Len(Me.txtScanCapture)
  15.     Case 3, 4
  16.         'Box
  17.         If strLastScan <> "Customer" Then
  18.             MsgBox "A customer ID must be scanned first before scanning boxes."
  19.         Else
  20.             'Is box registered in database?
  21.             If DCount("BOX_NUM", _
  22.                       "tblBOX", _
  23.                       "BOX_NUM='" & Me.txtScanCapture & "'") = 0 Then
  24.                 'Box does not exist in DB
  25.                 MsgBox "Box " & Me.txtScanCapture & " not recognized in tool"
  26.             Else
  27.                 Me.txtScan_Box_Num = Me.txtScanCapture
  28.                 'Box exists.
  29.                 'Assign box to current customer, set shipping date=now, and received date to null
  30.                 strSQL = "UPDATE tblBOX " & _
  31.                          "SET    [CUST_NUM]='" & Me.tb_Scan_Cust_Num & "'" & _
  32.                               ", [ORDER_NUM]='" & Me.Max_ORDER_NUM & "'" & _
  33.                               ", [DATE_BOX_SHIP]=Date()" & _
  34.                               ", [DATE_BOX_RETURN]=Null " & _
  35.                          "WHERE  ([BOX_NUM]='" & Me.txtScanCapture & "')"
  36.                 DoCmd.SetWarnings (False)
  37.                 DoCmd.RunSQL strSQL
  38.                 DoCmd.SetWarnings (True)
  39.                 Me.subfrmBOX_SHIPPING.Requery
  40.                 'Update the DATE_SHIP in tblOrders where necessary
  41.                 With db.OpenRecordset("tblORDERS", dbOpenDynaset)
  42.                     Call .FindFirst("[Order_Num]='" & Me.Max_ORDER_NUM & "'")
  43.                     If Not .NoMatch Then
  44.                         If IsNull(![DATE_SHIP]) Then
  45.                             Call .Edit
  46.                             ![DATE_SHIP] = Date
  47.                             Call .Update
  48.                          End If
  49.                     End If
  50.                     Call .Close
  51.                 End With
  52.             End If
  53.             strLastScan = "Box"
  54.             Me.tb_Scan_Cust_Num.BackStyle = 1
  55.             Me.txtScan_Box_Num.BackStyle = 0
  56.         End If
  57.  
  58.     Case 5
  59.         'Customer
  60.         'Lets find customer entered
  61.         strSQL = "SELECT   [CUST_NUM]" & _
  62.                         ", Max([ORDER_NUM]) As MaxOfORDER_NUM " & _
  63.                  "FROM     tblORDERS " & _
  64.                  "WHERE    [CUST_NUM]='" & Me.txtScanCapture & "'" & _
  65.                  "GROUP BY [CUST_NUM]"
  66.         With db.OpenRecordset(strSQL, dbOpenSnapshot)
  67.             If .RecordCount = 0 Then
  68.                 MsgBox "Customer number not recognized"
  69.                 'Do whatever you want to handle this case
  70.             Else
  71.                 strLastScan = "Customer"
  72.                 Me.tb_Scan_Cust_Num.BackStyle = 1
  73.                 Me.txtScan_Box_Num.BackStyle = 1
  74.                 Me.tb_Scan_Cust_Num = !CUST_NUM
  75.                 Me.Max_ORDER_NUM = !MaxOfORDER_NUM
  76.             End If
  77.             Call .Close
  78.         End With
  79.  
  80.     Case Else
  81.         'Some sort of error or user error
  82.         MsgBox "Input error, resetting"
  83.     End Select
  84.  
  85.     Me.txtScanCapture = ""
  86. End Sub
  87.  
Can someone please tell me what to do to get back my focus in that one field? The field is unbound and is named txtScanCapture. A fast response gets bonus points! ;-) Thanks in advance!!

FOLLOW UP: I just tried to remove the fields I had previously added, and tried to make it look like it was before, and I still couldn't get my focus back in that one box. (I hope my terminology is corret.) :-(
Apr 19 '11 #1
8 2207
TheSmileyCoder
2,322 Expert Mod 2GB
Its a bit hard without the database in front of me, but to me it sounds like it has something to do with TAB ORDER and tab stop.

The default behavior of access when pressing ENTER is to move to the next field. In fact that is part of whats trigging the after update to run.

2 things to look at:
In design view, you can right click on any "empty" space in the form, and view the tab order. That is the order in which controls gain focus, upon using the TAB button, or in some cases pressing enter. (Except for buttons which will actually run the code behind the buttons if the button has the focus when pressing enter). For each control you can view the tab stop property, which indicates whether or not the focus should "stop" at that control, or skip it. This again can be overwritten or overruled by such things as the enabled property. A not-enabled control will be stopped at while tabbing, even if tab stop is set to true.
To sum up:
Disable the extra controls you have added. If they are just for viewing data and not for manipulating data, they should likely be disabled anyway, or as a minimum they should be locked. If disabling/locking them is not good for you, you could try looking/playing with the tab order and tab stop properties.

2nd thing to try, which is probably the simplest, allthough I wont guarantee it will work. A the bottom of your code add the 2nd line of the 2 shown below:
Expand|Select|Wrap|Line Numbers
  1.   Me.txtScanCapture = ""
  2.   Me.txtScanCapture.SetFocus
  3. End Sub

Good luck with the baby.
Apr 20 '11 #2
TheSmileyCoder
2,322 Expert Mod 2GB
I wrote this small piece of code for you. Sadly it is completely unrelated to your (coding) issue. Try it out anyway!
Expand|Select|Wrap|Line Numbers
  1. Public Sub DanicaDear()
  2.     Dim strMsg As String
  3.     strMsg = strMsg & Chr(84)
  4.     strMsg = strMsg & Chr(104)
  5.     strMsg = strMsg & Chr(101)
  6.     strMsg = strMsg & Chr(32)
  7.     strMsg = strMsg & Chr(83)
  8.     strMsg = strMsg & Chr(109)
  9.     strMsg = strMsg & Chr(105)
  10.     strMsg = strMsg & Chr(108)
  11.     strMsg = strMsg & Chr(101)
  12.     strMsg = strMsg & Chr(121)
  13.     strMsg = strMsg & Chr(32)
  14.     strMsg = strMsg & Chr(67)
  15.     strMsg = strMsg & Chr(111)
  16.     strMsg = strMsg & Chr(100)
  17.     strMsg = strMsg & Chr(101)
  18.     strMsg = strMsg & Chr(114)
  19.     strMsg = strMsg & Chr(32)
  20.     strMsg = strMsg & Chr(87)
  21.     strMsg = strMsg & Chr(105)
  22.     strMsg = strMsg & Chr(115)
  23.     strMsg = strMsg & Chr(104)
  24.     strMsg = strMsg & Chr(101)
  25.     strMsg = strMsg & Chr(115)
  26.     strMsg = strMsg & Chr(32)
  27.     strMsg = strMsg & Chr(68)
  28.     strMsg = strMsg & Chr(97)
  29.     strMsg = strMsg & Chr(110)
  30.     strMsg = strMsg & Chr(105)
  31.     strMsg = strMsg & Chr(99)
  32.     strMsg = strMsg & Chr(97)
  33.     strMsg = strMsg & Chr(32)
  34.     strMsg = strMsg & Chr(68)
  35.     strMsg = strMsg & Chr(101)
  36.     strMsg = strMsg & Chr(97)
  37.     strMsg = strMsg & Chr(114)
  38.     strMsg = strMsg & Chr(32)
  39.     strMsg = strMsg & Chr(71)
  40.     strMsg = strMsg & Chr(111)
  41.     strMsg = strMsg & Chr(111)
  42.     strMsg = strMsg & Chr(100)
  43.     strMsg = strMsg & Chr(32)
  44.     strMsg = strMsg & Chr(76)
  45.     strMsg = strMsg & Chr(117)
  46.     strMsg = strMsg & Chr(99)
  47.     strMsg = strMsg & Chr(107)
  48.     strMsg = strMsg & Chr(32)
  49.     strMsg = strMsg & Chr(87)
  50.     strMsg = strMsg & Chr(105)
  51.     strMsg = strMsg & Chr(116)
  52.     strMsg = strMsg & Chr(104)
  53.     strMsg = strMsg & Chr(32)
  54.     strMsg = strMsg & Chr(84)
  55.     strMsg = strMsg & Chr(104)
  56.     strMsg = strMsg & Chr(101)
  57.     strMsg = strMsg & Chr(32)
  58.     strMsg = strMsg & Chr(66)
  59.     strMsg = strMsg & Chr(97)
  60.     strMsg = strMsg & Chr(98)
  61.     strMsg = strMsg & Chr(121)
  62.     strMsg = strMsg & Chr(33)
  63.  
  64.     Dim strTitel As String
  65.     strTitel = strTitel & Chr(65)
  66.     strTitel = strTitel & Chr(32)
  67.     strTitel = strTitel & Chr(83)
  68.     strTitel = strTitel & Chr(109)
  69.     strTitel = strTitel & Chr(105)
  70.     strTitel = strTitel & Chr(108)
  71.     strTitel = strTitel & Chr(101)
  72.     strTitel = strTitel & Chr(121)
  73.     strTitel = strTitel & Chr(32)
  74.     strTitel = strTitel & Chr(67)
  75.     strTitel = strTitel & Chr(111)
  76.     strTitel = strTitel & Chr(100)
  77.     strTitel = strTitel & Chr(101)
  78.     strTitel = strTitel & Chr(114)
  79.     strTitel = strTitel & Chr(32)
  80.     strTitel = strTitel & Chr(71)
  81.     strTitel = strTitel & Chr(114)
  82.     strTitel = strTitel & Chr(101)
  83.     strTitel = strTitel & Chr(101)
  84.     strTitel = strTitel & Chr(116)
  85.     strTitel = strTitel & Chr(105)
  86.     strTitel = strTitel & Chr(110)
  87.     strTitel = strTitel & Chr(103)
  88.  
  89.     MsgBox strMsg, vbOKOnly, strTitel
  90. End Sub
Apr 20 '11 #3
DanicaDear
269 256MB
Smiley,
Thanks for your reply! I think you may be on to something with the tab order. When I was discussing this DB earlier today with the users (who are unfamiliar with Access at all!) they noted that if you just press [enter] two extra times it gets you back to the right field. Of course this won't help with a scanner, but it definitely tipped me off on checking out the tab settings. It will be next week before I can give this a try.
PS. I did have the viewing fields locked. but I'm not sure what you mean by "disable" them. But I'll see what I can find out. Sounds rather simple. (seems like everytime I say that it's the hardest thing ever! ha).

I'll check out your special message soon! :-) Maybe tomorrow while I'm in labor. :-)

Thanks!!!!!!!!!!!!!!
Apr 20 '11 #4
NeoPa
32,556 Expert Mod 16PB
Smiley, I expect line #33 is superfluous. Only you can say if lines #6 and #13 should be there of course :-D

Danica, I'm sorry to say that I missed the time-frame for this one (though congratulations to Smiley for stepping in so quickly). Give me a shout on Skype when you're comfortably at home with your new offspring. If they're as as pretty as their older sister (and their mum of course) then you'll be well blessed. What am I talking about??!? You're well blessed in any case.

Best wishes to you and yours and let us know if you're still struggling with this.
Apr 21 '11 #5
DanicaDear
269 256MB
We found the problem!
Genius, (yes, me, haha) added two controls beneath the subform accidentally that you couldn't see. The tab stops were going to those fields. This was just a STUPID mistake...there was nothing wrong with the code or the DB. Lesson here is be mindful of things you can't see. :-)
THANKS EVERYONE!!!!!
Apr 26 '11 #6
NeoPa
32,556 Expert Mod 16PB
Don't forget to comment on Smiley's code Danica :-D I expect you'll like it.
Apr 27 '11 #7
DanicaDear
269 256MB
I definetely like Smiley's code....I think I might just leave that in my DB....so everytime they open a certain form it will load in there. Hahahaha!

You're sweet Smiley, and thanks for your quick response on my problem. I learned from your entry. I was perplexed how none of that was working. I had to laugh when NeoPa found the two controls under my subform. I'm a dork sometimes. LOL. :-)
Apr 27 '11 #8
TheSmileyCoder
2,322 Expert Mod 2GB
Whether its any consolation or not, I have done something similar before, with "loosing" controls that got placed below another object.

Glad you liked the code.
Apr 27 '11 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: lawrence | last post by:
Is there an easy way to sort a 2 dimensional array alphabetically by the second field in each row? Also, when I use sort() on a two dimensional array, it seems to work a lot like...
6
by: Geoff | last post by:
When trying to focus a field in Firefox, I get the following error: Error: " nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "JS frame ::...
1
by: Simon Gare | last post by:
Hi I need to compare a dynamic field in an asp page to a field in another table, if there is no match then i would like to chane the row colour ( see code below). The problem Im having is...
3
by: D Denholm | last post by:
I am a Access newbie... Hopefully somebody can help me figure this out. I have a database that looks like: Asset Economic Minimum ----- ---------------- 10555 ...
6
by: QT | last post by:
Dear sirs, I want to create panel or label field for each database records. I am using following codes for each database row to create panel field. 'Panel ' i = 1
1
by: Adrian Parker | last post by:
v1.1 - After taking off smartnav (due to it not working properly), I've got code that will restore the scroll position of the page on postback, but now I'm looking at how to set focus on either a...
3
by: larry | last post by:
Hi, Is there a way to calculate the sum of the numbers in each field for each record in the recordset returned from the query? Do I have to use VBScript? Thanks, Larry
1
by: Will_uk | last post by:
I am trying to return focus to a form input field. If i use <form>.<field>.focus() the focus returns to the field but if the field already contains a value it selects it (blacks it out). Is it...
2
by: donpro | last post by:
Hi, I have a form with date fields, I have created event listeners to check for a validate when leaving the field (onblur). If invalid, I need it to set the field back to the default value,...
4
by: Shalini Bhalla | last post by:
i have written following code for for checking required field . function validate_required(field,alerttxt) { with (field) { if (value==null||value=="") {alert(alerttxt); focus(); return...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.