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


P: 58
Hello again,

I have a form in columner style. I have the user enter in a area (dropdown) and a bag number. The program then searches the table to see if these are already added. If it is it gives an error, then is supposed to set the focus back on the bag number. Problem is it does not, it sets the focus on the next textbox. It does set the focus for about a half a second then goes to the next box.

i have the code in the hole number got focus sub. I dont know if this is the wrong spot.
Oct 16 '07 #1
Share this Question
Share on Google+
8 Replies

Expert Mod 10K+
P: 12,366
You have to put it in the lost focus of area and bag number.
Oct 16 '07 #2

P: 58
I put it in the lost focus but it is still doing this. Any suggestions?
Oct 29 '07 #3

Expert Mod 10K+
P: 12,366
What's the code you're using?
Oct 29 '07 #4

P: 58
Expand|Select|Wrap|Line Numbers
  1. Private Sub Bag_No_LostFocus()
  2.     Dim rst As Object
  3.     Dim db As Object
  4.     Dim intmsg As Integer
  6.     Set db = CurrentDb
  7.     Set rst = db.openrecordset("bags recieved")
  8.     rst.MoveFirst
  9.     Do While Not rst.EOF
  11.         If rst("hole no").Value = Me.Hole_No.Value And rst("bag no").Value = Me.Bag_No.Value Then
  12.             If rst("area").Value = Me.Combo29.Value Then
  13.                 intmsg = MsgBox("That bag and hole have already been used, you cannot add the bag again.", vbOKOnly, "Bag Error")
  14.                 Me.Bag_No.SetFocus
  15.                Exit Sub
  16.             End If
  17.         End If
  18.         rst.MoveNext
  19.     Loop
  20.     rst.Close
  21.     Set rst = Nothing
  22. End Sub
The bags are brought to us as follows: LDD-070-5A or 120-07-007-5A (just an example). The problem I was having was that the people entering in the info were entering them in wrong. I now have it set up that the user selects the area (LDD, STW, or 120) from a drop down box. When they move over to enter in the hole number (the next set of numbers. either -##-### or -###) it changes the input mask accordingly. From there they enter in the bag number. So I have the system check the 3 sections accordingly. I have tried it with the exit sub and without. neither works. I hope this makes sense.

Oct 29 '07 #5

Expert Mod 10K+
P: 12,366
I can't find anything explicitly wrong with the code. Have you stepped through the code in debug mode to see if it's running and triggering correctly? I use a similar process on my forms to set focus if they violate a validation rule.

The lost focus event is the event to use. Does the message box appear, it sets focus, and then the focus changes? This might be due to other code triggering. But if no other code is triggering, then there's no reason the code shouldn't work.
Oct 29 '07 #6

P: 58
I have stepped through and it seems to work fine there. The message box pops up. From there it sets the focus to the bag_no for like a half a second, then it goes on to the next box. I have similar code for the next box (which is tag_no) and it does the same thing. I will keep messin with it. If I get it figured out, i will let you know.

Oct 30 '07 #7

P: 58
I got it to work. I added a boolean in the lostfocus sub, i set it to false at the beginning of this sub and change it to true right before the exit sub line. I also took out the bag_no.setfocus line out. In the tag_no Got focus sub i added the following.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Tag_No_GotFocus()
  2.     If blnTest = True Then
  4.         Me.Bag_No.SetFocus
  6.     End If
  7. End Sub
Thank you Rabbit for all your help. It is greatly appreciated.

Oct 30 '07 #8

Expert 2.5K+
P: 3,532
There are a number of events in Access where common sense would tell you that a control no longer has focus, and thus you should be able to set focus on it. Unfortunately, things are not always as they seem! In LostFocus, OnExit and AfterUpdate (and maybe some others I didn't test) you cannot set focus to the object that belongs to the event! You have to move focus to another object and then back to the desired object. So for Bag_No you'd do something like this:

Expand|Select|Wrap|Line Numbers
  1.   Private Sub BagNo_LostFocus()
  2.    AnyOtherTextBox.SetFocus
  3.    Bag_No.SetFocus
  4.   End Sub
Linq ;0)>
Oct 30 '07 #9

Post your reply

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