473,396 Members | 1,891 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.

set focus after data validation

3
I have a simple sub-form based on a table in datasheet view and validate data in an afterupdate event procedure. When the data fails validation I display a message box and ask if the user wants to continue or go back and fix the data. I can't seem to set the focus back to the field that had the validation failure; it always just moves to the next field (InvQtyF)

This is what I have:

If Nz(DLookup("[Manufactures_ID]", "Item Master Local", "[Manufactures_ID]='" & Me.ManufItem & "'")) Then
Exit Sub
Else
If MsgBox("Non-Existant Product Code, Re-enter?", vbYesNo, "Error!") = vbYes Then
Me.ManufItemF.SetFocus
Else
Me.InvQtyF.SetFocus
End If
End If
End Sub

The field name on the form is ManufItemF whereas the field in the underlying table is ManufItem. I also tried Me.ActiveControl.SetFocus with same results.

Sorry for the lack of indentation,

Thanks for any help/pointers.....
Nov 19 '07 #1
6 7336
ADezii
8,834 Expert 8TB
I have a simple sub-form based on a table in datasheet view and validate data in an afterupdate event procedure. When the data fails validation I display a message box and ask if the user wants to continue or go back and fix the data. I can't seem to set the focus back to the field that had the validation failure; it always just moves to the next field (InvQtyF)

This is what I have:

If Nz(DLookup("[Manufactures_ID]", "Item Master Local", "[Manufactures_ID]='" & Me.ManufItem & "'")) Then
Exit Sub
Else
If MsgBox("Non-Existant Product Code, Re-enter?", vbYesNo, "Error!") = vbYes Then
Me.ManufItemF.SetFocus
Else
Me.InvQtyF.SetFocus
End If
End If
End Sub

The field name on the form is ManufItemF whereas the field in the underlying table is ManufItem. I also tried Me.ActiveControl.SetFocus with same results.

Sorry for the lack of indentation,

Thanks for any help/pointers.....
I have a simple sub-form based on a table in datasheet view and validate data in an afterupdate event procedure.
Data Validation should occur in the BeforeUpdate() not AfterUpdate() Event.
  1. Do you want to perform Data Validation at the Field or Form level?
  2. What is the Name of the Main Form?
  3. What is the Name of the Sub-Form?
  4. What is the Name of the Sub-Form Control?
  5. Is the [ManufItem] Field on the Main Form or Sub-Form?
  6. Is the [InvQtyF] Field on the Main Form or Sub-Form?
Nov 20 '07 #2
ned610
3
Data Validation should occur in the BeforeUpdate() not AfterUpdate() Event.
  1. Do you want to perform Data Validation at the Field or Form level?
  2. What is the Name of the Main Form?
  3. What is the Name of the Sub-Form?
  4. What is the Name of the Sub-Form Control?
  5. Is the [ManufItem] Field on the Main Form or Sub-Form?
  6. Is the [InvQtyF] Field on the Main Form or Sub-Form?
First thanks for looking at this:

I tried moving my code to the BeforeUpdate() Event and it whined about not saving the field first and said it should be in the AfterUpdate() event so I guess it's not as easy as just moving the code....

1-I am validating that the data entered in the ManufItemF form field exists in the Item Master table; that part works OK.
It's just that after getting a response to the MsgBox I can't get the focus back to the ManufItemF field for the user to correct their input.
I have to allow them to make an entry that doesn't exist in the Item Master table but want to warn them in case it was just a typo.

2-The main form name is: InventoryItemsMasterForm

3-The Sub-Form is: InvItemsForm (which is in datasheet view) whose record source is InvItemsTbl (not that that matters)

4-The field ManufItem (Control Source) is in the underlying table, the field name on the form is ManufItemF
(I added the "F" at the end of the form field name in case it was a problem having the data field in the underlying table and form field name the same;
that didn't help me with the focus problem though)

5-The InvQtyF field is on the sub-form.
Nov 20 '07 #3
missinglinq
3,532 Expert 2GB
There are events whose names, such as AfterUpdate, would lead you to believe that their control has lost focus, when it really hasn't! One would think, for instance, that by the time the event MyTextBox_AfterUpdate was reached, that the control MyTextBox had lost focus, and thus focus could once again be set to it. Not true! It still has (well, sort of) focus! What you need to do, in these circumstances, is to set the focus to any other control on your form, then set it back to the target control!

ADezii is correct in saying that Validation needs to be done in the BeforeUpdate events of either a given control or the form. AfterUpdate events are generally used not for vaidation but rather for formatting data that has already entered. The BeforeUpdate whining, I believe, was caused by your Exit Sub line, which was basically causing the sub to abort before the save was complete.

Welcome to TheScripts!

Linq ;0)>
Nov 20 '07 #4
ADezii
8,834 Expert 8TB
First thanks for looking at this:

I tried moving my code to the BeforeUpdate() Event and it whined about not saving the field first and said it should be in the AfterUpdate() event so I guess it's not as easy as just moving the code....

1-I am validating that the data entered in the ManufItemF form field exists in the Item Master table; that part works OK.
It's just that after getting a response to the MsgBox I can't get the focus back to the ManufItemF field for the user to correct their input.
I have to allow them to make an entry that doesn't exist in the Item Master table but want to warn them in case it was just a typo.

2-The main form name is: InventoryItemsMasterForm

3-The Sub-Form is: InvItemsForm (which is in datasheet view) whose record source is InvItemsTbl (not that that matters)

4-The field ManufItem (Control Source) is in the underlying table, the field name on the form is ManufItemF
(I added the "F" at the end of the form field name in case it was a problem having the data field in the underlying table and form field name the same;
that didn't help me with the focus problem though)

5-The InvQtyF field is on the sub-form.
Try the following code in the BeforeUpdate() Event of the [ManufItem] Field:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ManufItem_BeforeUpdate(Cancel As Integer)
  2. If Nz(DLookup("[Manufactures_ID]", "Item Master Local", "[Manufactures_ID]='" & Me.ManufItem & "'")) = "" Then
  3.   If MsgBox("Non-Existant Product Code, Re-enter?", vbYesNo, "Error!") = vbYes Then
  4.     Cancel = True        'will not be able to leave the Field
  5.   Else
  6.     'You cannot SetFocus to a Field in this Event, since data in this Field must
  7.     'first be saved. To get aroud this, simply set the Tab Index of the [InvQtyF]
  8.     'Field to 1 greater than the [ManufItem] Field.
  9.   End If
  10. End If
  11. End Sub
  12.  
Nov 20 '07 #5
ned610
3
Try the following code in the BeforeUpdate() Event of the [ManufItem] Field:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ManufItem_BeforeUpdate(Cancel As Integer)
  2. If Nz(DLookup("[Manufactures_ID]", "Item Master Local", "[Manufactures_ID]='" & Me.ManufItem & "'")) = "" Then
  3.   If MsgBox("Non-Existant Product Code, Re-enter?", vbYesNo, "Error!") = vbYes Then
  4.     Cancel = True        'will not be able to leave the Field
  5.   Else
  6.     'You cannot SetFocus to a Field in this Event, since data in this Field must
  7.     'first be saved. To get aroud this, simply set the Tab Index of the [InvQtyF]
  8.     'Field to 1 greater than the [ManufItem] Field.
  9.   End If
  10. End If
  11. End Sub
  12.  
Thank you very much.... That solved the issue, that was way too easy!!!
Nov 20 '07 #6
ADezii
8,834 Expert 8TB
Thank you very much.... That solved the issue, that was way too easy!!!
I'm glad it worked out for you.
Nov 20 '07 #7

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

Similar topics

5
by: 'bonehead | last post by:
Greetings, I'm still something of a newbie to html/php/mysql. I have a php/html form with several fields of type "input". If the user enters improper data in a particular field and clicks the...
3
by: Dan | last post by:
This function validates a price field on my form. It fires with onchange. If the validation fails, I want the focus to return to the same field so that the user can correct it. The way it is...
4
by: Nitin | last post by:
Hi I have created function to check date and time. at the time of execution, if date is left empty the function returns the error message but then the focus goes to next field. Next filed is for...
5
by: tshad | last post by:
I have a date validation function that I want to stay at the object I am validating if there is a Validation error, but it always goes to the next object. The Javascript: function...
0
by: ED M. | last post by:
Hello all...I'm new to the board. I have a problem that I hope someone here might be able to solve for me. I am doing some clientside validation using Javascript. The text I am testing is...
4
by: SJ | last post by:
Hi all, I have come across a weird problem when attempting to automatically set the focus in a vb.net form to a checkbox control... In my form I have (on a tab page in a tab control) several...
4
by: bienwell | last post by:
Hi, I have a problem and really need your help. In my web page ASPX, I have some text fields to accept data from users. I did form validation like this : <td class="dataTD" style="HEIGHT:...
3
by: vivela | last post by:
hi, I hope you could help me out on this one,cause I have been trying for 4 days to solve it,but couldn't quite get it right: I have an ASP textbox that should change the value in a dropdownlist....
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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
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
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...

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.