473,405 Members | 2,445 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,405 software developers and data experts.

gotfocus

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.
Andrew
Oct 16 '07 #1
8 6052
Rabbit
12,516 Expert Mod 8TB
You have to put it in the lost focus of area and bag number.
Oct 16 '07 #2
I put it in the lost focus but it is still doing this. Any suggestions?
Oct 29 '07 #3
Rabbit
12,516 Expert Mod 8TB
What's the code you're using?
Oct 29 '07 #4
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
  5.  
  6.     Set db = CurrentDb
  7.     Set rst = db.openrecordset("bags recieved")
  8.     rst.MoveFirst
  9.     Do While Not rst.EOF
  10.  
  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
  23.  
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.

Andrew
Oct 29 '07 #5
Rabbit
12,516 Expert Mod 8TB
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
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.

Andrew
Oct 30 '07 #7
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
  3.  
  4.         Me.Bag_No.SetFocus
  5.  
  6.     End If
  7. End Sub
  8.  
Thank you Rabbit for all your help. It is greatly appreciated.

Andrew
Oct 30 '07 #8
missinglinq
3,532 Expert 2GB
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

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

Similar topics

0
by: Krisa | last post by:
Hello all, I just discovered something (stop me if you've heard this before....) that was causing me a significant performance hit when opening a form with subforms. To speed up loading the...
6
by: lauren quantrell | last post by:
I have a combo box on a form. It uses the GotFocus event to poopulate the rowsource with a value list that is created on the fly in VBA. Fine and dandy, except, is a user opens another form and...
0
by: Tom Hartnett | last post by:
This seems like it ought to be a simple thing. I am long accustomed to using the GotFocus event in VB6 to select the text in a textbox when the control is clicked in or tabbed into. C# doesn't...
2
by: Gopal Krishna Tengli | last post by:
Hi, I want to impliment the textbox's gotfocus event. Its not a intrincic event. So not listed in the editor. Waiting for an innovative reply... Gopal Krishna
2
by: James Wong | last post by:
Hi! everybody, I want my control to have different behavior if it got focus by mouse click from by keyboard (i.e. Tab or Shift-Tab). I found that GotFocus event always comes before MouseDown...
4
by: dudzcom | last post by:
hi, this is the first time i've posted to this board, though i have been a devoted lurker for some time i have been working in vb.net and run into a couple problems that seem to require solutions...
1
by: Nathan Franklin | last post by:
I have a DataGridView on my windows form and I am trying to enable buttons on a toolbar when the DataGridView's GotFocus is called and then disable with LostFocus(). The problem is I can only get...
2
by: Boki | last post by:
Dear All, What is the different between Enter and GotFocus events? Best reagrds, Boki.
2
by: Jason Huang | last post by:
Hi, In my .Net 1.1 C# windows form Form1 I have nothing but 2 TextBox controls on the Form1, the T1 and T2. I would like to test the sequence of the GotFocus LostFocus things, so I have the...
1
by: moondaddy | last post by:
I have a c# 3.5 wpf app which uses user controls for data entry screens. These data entry screens can be nested inside of each. We can also have several ones open side by side at the same time. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.