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! -
Private Sub checkValid()
-
If [Forms]![Students]!residentOf <> "CA" And Source Like "IN*" Then
-
MsgBox "Cannot Using Instate source for a student out of CA"
-
Source.SetFocus
-
End If
-
End Sub
-
-
Private Sub Source_AfterUpdate()
-
Call checkValid
-
End Sub
-
8 1648
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! -
Private Sub checkValid()
-
If [Forms]![Students]!residentOf <> "CA" And Source Like "IN*" Then
-
MsgBox "Cannot Using Instate source for a student out of CA"
-
Source.SetFocus
-
End If
-
End Sub
-
-
Private Sub Source_AfterUpdate()
-
Call checkValid
-
End Sub
-
Try qualifying your Source.SetFocus line... i.e. either Me!Source.SetFocus, or Forms![FormName].Source.SetFocus
Regards,
Scott
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.
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.
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!
how and where to set the cancel=true?
thanks.
It's wonderful!!
i set cancel=true , and it worked as magic.
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
how and where to set the cancel=true?
thanks.
Nice, you've made it work.
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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,...
|
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...
|
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...
|
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)
{...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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
|
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: 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...
| |