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
8 6052
You have to put it in the lost focus of area and bag number.
I put it in the lost focus but it is still doing this. Any suggestions?
What's the code you're using?
-
Private Sub Bag_No_LostFocus()
-
Dim rst As Object
-
Dim db As Object
-
Dim intmsg As Integer
-
-
Set db = CurrentDb
-
Set rst = db.openrecordset("bags recieved")
-
rst.MoveFirst
-
Do While Not rst.EOF
-
-
If rst("hole no").Value = Me.Hole_No.Value And rst("bag no").Value = Me.Bag_No.Value Then
-
If rst("area").Value = Me.Combo29.Value Then
-
intmsg = MsgBox("That bag and hole have already been used, you cannot add the bag again.", vbOKOnly, "Bag Error")
-
Me.Bag_No.SetFocus
-
Exit Sub
-
End If
-
End If
-
rst.MoveNext
-
Loop
-
rst.Close
-
Set rst = Nothing
-
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.
Andrew
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.
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
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. -
Private Sub Tag_No_GotFocus()
-
If blnTest = True Then
-
-
Me.Bag_No.SetFocus
-
-
End If
-
End Sub
-
Thank you Rabbit for all your help. It is greatly appreciated.
Andrew
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: - Private Sub BagNo_LostFocus()
-
AnyOtherTextBox.SetFocus
-
Bag_No.SetFocus
-
End Sub
Linq ;0)> Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
by: Boki |
last post by:
Dear All,
What is the different between Enter and GotFocus events?
Best reagrds,
Boki.
|
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...
|
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. ...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |