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

Lost Focus Got Focus I cannot Focus

134 100+
I am trying to validate a QTY entry in a form , if user did not enter anything or 0 , I will prompt for a message and the cursor return to the QTY entry column.

I have tried Lost Focus in the Qty -

If qty <=0 then
msgbox("Please Enter Qty")
me.qty.SetFocus
end if

But the cursor alway jump to the next entry box, I even replace with Cancel=true, it still doesnt work, Any Idea ?
Dec 15 '06 #1
16 12989
MMcCarthy
14,534 Expert Mod 8TB
I am trying to validate a QTY entry in a form , if user did not enter anything or 0 , I will prompt for a message and the cursor return to the QTY entry column.

I have tried Lost Focus in the Qty -

If qty <=0 then
msgbox("Please Enter Qty")
me.qty.SetFocus
end if

But the cursor alway jump to the next entry box, I even replace with Cancel=true, it still doesnt work, Any Idea ?
Change to After Update event.

Expand|Select|Wrap|Line Numbers
  1. Private Sub qty_AfterUpdate()
  2.  
  3.    If IsNull(Me.qty) Or Me.qty <=0 Then
  4.       Msgbox "Please Enter Qty", vbOKOnly
  5.       Me.qty = Null
  6.       Me.qty.SetFocus
  7.    End If
  8.  
  9. End Sub
  10.  
Mary
Dec 15 '06 #2
jamesnkk
134 100+
But what if user press the Tab key or move the mouse away from this text box, then I don't think After Update could detect it, Am I Right ?
Dec 15 '06 #3
MMcCarthy
14,534 Expert Mod 8TB
But what if user press the Tab key or move the mouse away from this text box, then I don't think After Update could detect it, Am I Right ?
Once the control has been entered it should trigger the after update event. However, to be sure, you just have to call the event in the forms OnClose event.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_OnClose()
  2.    qty_AfterUpdate
  3. End Sub
  4.  
Mary
Dec 15 '06 #4
jamesnkk
134 100+
The Qty entry column is default display at 0, if you press enter or tab or move your mouse away, the After Update cannot detect, I can only detect using Lost Focus, but it doesn't stay focus, even I issue setfocus, will just skip to next entry column,

Why should I use On Form Close, I want interactive repsonse to the user, don;t you think it right ?
Dec 15 '06 #5
MMcCarthy
14,534 Expert Mod 8TB
The Qty entry column is default display at 0, if you press enter or tab or move your mouse away, the After Update cannot detect, I can only detect using Lost Focus, but it doesn't stay focus, even I issue setfocus, will just skip to next entry column,

Why should I use On Form Close, I want interactive repsonse to the user, don;t you think it right ?
Try the Before Update event.

Form On Close is just a catch all.

Mary
Dec 15 '06 #6
NeoPa
32,556 Expert Mod 16PB
James,

Try it out as Mary suggests.
If you find it doesn't really work as you want it, then come back and explain why the answer isn't right.
I suspect that using the focus to trigger would actually cause you more problems than you expect.
Dec 15 '06 #7
Hi there,

I have seen ur code why don't you try validate method of text box it works really nice in these cases.

gaurav
Dec 16 '06 #8
jamesnkk
134 100+
Hi there,

I have seen ur code why don't you try validate method of text box it works really nice in these cases.

gaurav
Are you Saying creating a text box such as txtQtyOrder instead of using the actual field name =QtyOrder
Dec 16 '06 #9
MMcCarthy
14,534 Expert Mod 8TB
Are you Saying creating a text box such as txtQtyOrder instead of using the actual field name =QtyOrder
I'm terrible at validation using the property as I do all mine in code but what the previous poster is talking about is using the validation property which you will find under the data tab I think.

At a guess I would say if you put the following in the validation property if should work.

Expand|Select|Wrap|Line Numbers
  1. QtyOrder>0
Mary
Dec 16 '06 #10
NeoPa
32,556 Expert Mod 16PB
Are you Saying creating a text box such as txtQtyOrder instead of using the actual field name =QtyOrder
Yup - that's about the size of it.
Consider Guarav's response though, that may be even easier for you.
Dec 16 '06 #11
jamesnkk
134 100+
I'm terrible at validation using the property as I do all mine in code but what the previous poster is talking about is using the validation property which you will find under the data tab I think.

At a guess I would say if you put the following in the validation property if should work.

Expand|Select|Wrap|Line Numbers
  1. QtyOrder>0
Mary
Let forget about using Before and After event, Is there a way the cursor can return to that fieldname-Qty in the Lost Focus validation ? I know using sendkey vbtab can be done, but that not the right way.
Dec 16 '06 #12
NeoPa
32,556 Expert Mod 16PB
Let forget about using Before and After event, Is there a way the cursor can return to that fieldname-Qty in the Lost Focus validation ? I know using sendkey vbtab can be done, but that not the right way.
Lost Focus is not a 'validation' attribute.
LostFocus is an event procedure but Validation properties (Validation Rule & Validation Text) are attributes of the field itself.
Entering values in these can cause Access to insist on any changes to the field being valid according to your specified rules.
Dec 17 '06 #13
hyperpau
184 Expert 100+
Let forget about using Before and After event, Is there a way the cursor can return to that fieldname-Qty in the Lost Focus validation ? I know using sendkey vbtab can be done, but that not the right way.
This may be long overdue but for sake of others looking for the solution:

Use instead the BeforeUpdate event as suggested above already.

Expand|Select|Wrap|Line Numbers
  1. Private Sub qty_BeforeUpdate (Cancel as Integer)
  2. If qty <=0 Then
  3. MsgBox("Please Enter Qty")
  4. Cancel = True
  5. End if
This will not set focus back but would actually prevent losing focus
whether by pressing TAB or by using mouse to move focus to other controls.
Aug 30 '08 #14
NeoPa
32,556 Expert Mod 16PB
This should work of course, but why would you suggest adding code to produce the same results as the standard method (of using Validation Rule & Validation Text) for such a simple example?
Aug 30 '08 #15
This may be long overdue but for sake of others looking for the solution:

Use instead the BeforeUpdate event as suggested above already.

Expand|Select|Wrap|Line Numbers
  1. Private Sub qty_BeforeUpdate (Cancel as Integer)
  2. If qty <=0 Then
  3. MsgBox("Please Enter Qty")
  4. Cancel = True
  5. End if
This will not set focus back but would actually prevent losing focus
whether by pressing TAB or by using mouse to move focus to other controls.
I have found a solution to the problem, it is definitely a workaround, but I think this is what is being asked for:

Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox1_LostFocus()
  2.  
  3.     If Len(Nz(Me.TextBox1, "")) = 0 Then
  4.         Me.TextBox2.SetFocus
  5.         Me.TextBox1.SetFocus
  6.     End If
  7.  
  8. End Sub
  9.  
Notes:
1. This is a test for a non-Null and non Zero length string
2. It uses another textbox as an interim target - this could be a textbox with its Visible property set to False.

If you want to control the onward direction from say Textbox1 to Textbox2, then simply adding the 'Else' construct does this fairly elegantly (although highly bespoked)

Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox1_LostFocus()
  2.  
  3.     If Len(Nz(Me.TextBox1, "")) = 0 Then
  4.         Me.TextBox2.SetFocus
  5.         Me.TextBox1.SetFocus
  6.     Else
  7.         Me.TextBox2.SetFocus
  8.     End If
  9.  
  10. End Sub
  11.  
Kind regards
Geoff
Sep 14 '08 #16
NeoPa
32,556 Expert Mod 16PB
...
Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox1_LostFocus()
  2.  
  3.     If Len(Nz(Me.TextBox1, "")) = 0 Then
  4.         Me.TextBox2.SetFocus
  5.         Me.TextBox1.SetFocus
  6.     Else
  7.         Me.TextBox2.SetFocus
  8.     End If
  9.  
  10. End Sub
...
This code is logically equivalent to :
Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox1_LostFocus()
  2.  
  3.     Me.TextBox2.SetFocus
  4.     If Len(Nz(Me.TextBox1, "")) = 0 Then Me.TextBox1.SetFocus
  5.  
  6. End Sub
Can you explain why this would help the situation. I'm a bit confused as to what this is saying :S
Sep 14 '08 #17

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

Similar topics

0
by: Christophe Poirier | last post by:
------=_NextPart_000_0023_01C35B54.206CFD60 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit I am working on a Windows 2000 server. The version 4.0.13 was...
6
by: Tony G. | last post by:
Hi there, I have an APS 3 application, running on a Windows 2003 Web edition server - it is a very busy website, and when users are click on certain links (membership info), a new window i...
2
by: Marius Horak | last post by:
Hi, TextBox myTextBox = new TextBox(); myTableCell.Controls.Add(myTextBox); When I execute this code and myTextBox is empty I cannot focus on myTextBox using mouse unless I click at the very...
11
by: Alex.Svetos | last post by:
Hello, I'm trying to get a popup to keep focus when it is re-clicked. The script below is supposed to produce this exact behaviour, however it doesn't work, at least on firefox 1.0.7 and moz...
4
by: Jon Slaughter | last post by:
Whats the difference? Thanks, Jon
4
by: Jon Slaughter | last post by:
I've created some custom controls and forms that allow the feature to temporarily transfer focus to a control that has been entered by the mouse. Everything seems to work fine but the problem I...
4
by: Roger | last post by:
Hi, I am confused about the differences between this.window.focus(), window.focus(), and this.focus(). I want to use the calls in a <body onload="..."tag. What are the differences between...
2
by: ismailc | last post by:
Hi, I would like to do the following. I have an href where onclick the focus is on the href: I got it to change focus to another object but i don't really want that. It must be as if the...
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
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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.