473,382 Members | 1,386 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,382 software developers and data experts.

Enforce a field type in after validation check

I have this form to input a student's tuition source, after the source is entered as 'instate' or 'out', there's a checking on whether the student is a CA resident. If not from CA, and the source is set up as 'Instate', then a msgbox pop up and indicates the wrong input. (the code is attached below)

While the problem I get is, after click 'ok' on the msgbox, i don't know how to make it stays in the wrong field and checking until it get right, I used setFocus to the 'Source' field, but it doesn't work as I expected, since I can navigate to other fields with the wrong thing not changed. I've struggled a whole afternoon, but don't know where to find the right answer. Thanks in advance for any inputs!

Expand|Select|Wrap|Line Numbers
  1. Private Sub checkValid()
  2.     If [Forms]![Students]!residentOf <> "CA" And Source Like "IN*" Then
  3.         MsgBox "Cannot Using Instate source for a student out of CA"
  4.         Source.SetFocus
  5.     End If
  6. End Sub
  7.  
  8. Private Sub Source_AfterUpdate()
  9.     Call checkValid
  10. End Sub
  11.  
Aug 20 '07 #1
8 1648
Scott Price
1,384 Expert 1GB
I have this form to input a student's tuition source, after the source is entered as 'instate' or 'out', there's a checking on whether the student is a CA resident. If not from CA, and the source is set up as 'Instate', then a msgbox pop up and indicates the wrong input. (the code is attached below)

While the problem I get is, after click 'ok' on the msgbox, i don't know how to make it stays in the wrong field and checking until it get right, I used setFocus to the 'Source' field, but it doesn't work as I expected, since I can navigate to other fields with the wrong thing not changed. I've struggled a whole afternoon, but don't know where to find the right answer. Thanks in advance for any inputs!

Expand|Select|Wrap|Line Numbers
  1. Private Sub checkValid()
  2.     If [Forms]![Students]!residentOf <> "CA" And Source Like "IN*" Then
  3.         MsgBox "Cannot Using Instate source for a student out of CA"
  4.         Source.SetFocus
  5.     End If
  6. End Sub
  7.  
  8. Private Sub Source_AfterUpdate()
  9.     Call checkValid
  10. End Sub
  11.  
Try qualifying your Source.SetFocus line... i.e. either Me!Source.SetFocus, or Forms![FormName].Source.SetFocus

Regards,
Scott
Aug 20 '07 #2
Try qualifying your Source.SetFocus line... i.e. either Me!Source.SetFocus, or Forms![FormName].Source.SetFocus

Regards,
Scott
Scott,
Thanks for the fast reply. the setFocus works fine, problem is after it gets focused, it doesn't enforce me to correct it, i can use 'tab' button to navigate to some other fields and the error is still there.

Plus, i don't know how to reference the Source as you suggested. this field is under a subform called [StudensAndFunding subform]. the main form is called [Students]. So, I tried [Students]!Source, [Students]![StudentsAndFunding subform]!source and Me!Source, none of them worked. but if I use just the field name as in my code, it works just fine. What's the 'Me' in my case? I wasn't a VB programer and am new in Access, it frustrates me sometimes.
Aug 20 '07 #3
FishVal
2,653 Expert 2GB
Scott,
Thanks for the fast reply. the setFocus works fine, problem is after it gets focused, it doesn't enforce me to correct it, i can use 'tab' button to navigate to some other fields and the error is still there.

Plus, i don't know how to reference the Source as you suggested. this field is under a subform called [StudensAndFunding subform]. the main form is called [Students]. So, I tried [Students]!Source, [Students]![StudentsAndFunding subform]!source and Me!Source, none of them worked. but if I use just the field name as in my code, it works just fine. What's the 'Me' in my case? I wasn't a VB programer and am new in Access, it frustrates me sometimes.
Try to handle it in Source_Exit event setting Cancel=True if validation fails.
Aug 20 '07 #4
Try to handle it in Source_Exit event setting Cancel=True if validation fails.
how and where to set the cancel=true?
thanks.

I found it. it worked great. thanks a million! it's such a wonderful forum!
Aug 20 '07 #5
how and where to set the cancel=true?
thanks.
It's wonderful!!
i set cancel=true , and it worked as magic.
Aug 20 '07 #6
Scott Price
1,384 Expert 1GB
It's wonderful!!
i set cancel=true , and it worked as magic.
Glad it works, and we were able to help!

Welcome to TSDN.

Regards,
Scott
Aug 20 '07 #7
FishVal
2,653 Expert 2GB
how and where to set the cancel=true?
thanks.
Nice, you've made it work.
Aug 20 '07 #8
Scott Price
1,384 Expert 1GB
Scott,
Thanks for the fast reply. the setFocus works fine, problem is after it gets focused, it doesn't enforce me to correct it, i can use 'tab' button to navigate to some other fields and the error is still there.

Plus, i don't know how to reference the Source as you suggested. this field is under a subform called [StudensAndFunding subform]. the main form is called [Students]. So, I tried [Students]!Source, [Students]![StudentsAndFunding subform]!source and Me!Source, none of them worked. but if I use just the field name as in my code, it works just fine. What's the 'Me' in my case? I wasn't a VB programer and am new in Access, it frustrates me sometimes.

For your information, when referring to a control on a subform, the proper syntax is: Forms![MainFormName]![SubFormName].Form![ControlName]

In your case, Access was smart enough to recognize what you were referring to :-)

The Me![ControlName] is used when referring to a control on the form which has the code module that contains the code you are running.

Regards,
Scott
Aug 20 '07 #9

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

Similar topics

3
by: TekWiz | last post by:
I've got a system that automatically generates a form. I have it set up so that the backend will return to the inital form page with an error object in sessions data (assuming the backend detected...
7
by: Mike | last post by:
I've been trying for the past week to put a simple code together. I have done a LOT of searching, found scripts showing the functions I would like to use, however when I mix them it all goes wrong,...
7
by: Tony Cooke | last post by:
Hi all. I'm not sure why I'm having problems with this but if I try to retrieve the value of a readonly text form I get back that the object is undefined. The reason the text is readonly is...
4
by: Darren | last post by:
How can I require a textbox only if a checkbox is checked. If the user checks the box for "fruit" then they have to enter the type of fruit If the user does not check the "fruit" box then they...
8
by: SAN CAZIANO | last post by:
i have to do in the onkeypress or in onchange the float (real) field validation I try something: function ValidaCampo(nomeCampo,TotInteri,TotDecimali) {...
4
by: peashoe | last post by:
I have an asp page that uses a calendar.js (pop-up) file to add an exact date format in the text field (txtDDate). My problem is I need some javascript that sets an alert that does not allow them...
8
by: Tony Williams | last post by:
I have a form where the user inputs a series of figures into a number of controls. After they've input the total (they don't want the program to create the total) there is a check to make sure the...
0
by: bienwell | last post by:
Hi, How can we focus on the field after the form validation. For example, user enter wrong data type on the field after validation (RegularExpressionvalidator), and I'd like to focus on that...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.