Modules & VBA :: Form Data Validation?
Jun 12, 2013I would like to write some code to validate that when a user enters data into a text field, the user must enter 4 digits.
View RepliesI would like to write some code to validate that when a user enters data into a text field, the user must enter 4 digits.
View RepliesI have 2 combo boxes on a form. The 2nd box is not visible unless the 1st box is set to a specific value (Illness). Once the specific value is set, the 2nd box appears with appropriate data for selection.
Goal #1:
I would like to have the form checked before it is closed to ensure that if the condition in box 1 is "Illness" then the 2nd box must have a value and can not be null.
Goal #2:
I am also having problems with the 2nd combo being visible when form opens or becomes current. The field is set to visible=false normally but needs to be visible when form opens if the conditions mentioned above are meet (true).
Private Sub Form_Unload()
If IsNull(Me.Incident_Classification) Then
MsgBox "Please select a type of Illness"
Me.Incident_Classification.SetFocus
]Code] .....
I am using following routine to lift data from Excel files into Access tables. Whole thing works, well, most of the time. The only issue I have is the spreadsheets are received from warehouses and even though they have been given strict instruction to stick to the template, I have had to adjust the spreadsheets. Amongst errors I get are:
Field 'F16' does not exist in table 'SA1'. (In this case I simply delete the last most empty column to fix this).
Or there are column name spellings and in such cases, I get no error and the simply code hangs.
Is there any routine that I could incorporate in the code that clearly states what issues are being experienced. This way I can pass the db to the user to run it themselves.
'Dim dbs As Database, tdf As TableDef
Set dbs = CurrentDb
On Error GoTo Macro1_Err
DoCmd.SetWarnings False
' RunSQL executes a SQL string
[Code] .....
There are 4 unbound dropdown list box that will have a default value of empty string. All 4 must have values entered (data is required).Once all 4 are required - the bottom 5 text box will become enabled (optional data).Forcing the user to click on a Validation Button
Some users type then use the mouse to select the next.Other users type to select then tab.The trick is: After filling in the 4th listbox and validating all 4 have values, the event must trigger code to enable the 5 optional text boxes below.This provides a seamless data entry environment.
I have been doing this in other places, but the transisition after the last required field is complete gets ugly.If Trim(cmbBoxname1 & "") = vbNullString ' check all 4..If it is the 4th one, the event seems not to happen quick enough for the bottom 5 text boxes to be enabled so the user can continue with data entry.
I am trying to validate data held in two controls on a form.
The first control records membership status and is a combobox with 5 values allowed.
1 is 'member'
2 is 'under consideration'
3 is 'left' etc.
The combobox displays the description, the underlying table the number 1-5.
The second control records 'reason for leaving' and again is a combobox with 7 entries just as above.
I need to ensure that if a value is entered into the second control the value of the first control is '1' or 'member'.
Whatever I do I cannot get any code to work.
So, what event should I link to the code attached to the second combobox? On lost focus, before update or what?
What value do I check for in the comboboxes, the text or the number?
How do I set focus back to the first combobox in the event of an error?
What I have:
Table named: clients table
Form named: clients data form
The form has the client information. The client sends me a document. I review the document. If the document has the correct info needed, then I have a field named "Incomplete" that is a Yes/No field in the clients table.If the field is clicked, then I want the next date field to appear and then I can fill in the date that it was sent back to them.If the field "incomplete" field is not checked, then I don't want that date field to appear nor do I want to fill it out.
I'm a BA so i'm converting my excel issues list into a database with a front end where i can create new issue records this uses a form that sits on top of the issues_table.
Howver, i have created a table called Projects and a table called Test_Plans
Each issue is logged against a project and a test plan. Lets say ProjectA has TestPlan1 and ProjectB has Testplan2.
On my issues form, i can select ProjectA in the project field.
In the Testplan field i can select EITHER TestPlan1 or Testplan2
Testplan1 is the only valid entry.
How do i
a) Once I have selected ProjectA in the Project field only display Testplan1 in the Testplan field?
or
b) If the user tries to enter testplan2 for it to error?
I've tried creating a query and linking the controlsource field to it but it doesn't like that!
I've two tables, QA (Quality Assurance) and Instruments. I'm using form to add data to QA.
There's a field in QA, named InstrumentUsed. The criteria is that InstrmentUsed should only accept value when 'status' field in Instruments table shows 'working'. If status is 'faulty' or 'need repair', it should pop up the related error message and cursor stays on the same field.
I've not starting learning VBA yet, so I'm trying to make use of Macro's.
How to use data from another table as a validation criteria for a field in form?
Pops up a MessageBox and stays on the same field, on the form, unless error is resolved?
I want to use the same form in datasheet mode for data entry and retrieval. When retrieving, all controls are disabled and locked. I am trying to enable and unlock them for modifying but that isn't working.
<code>
DoCmd.OpenForm "PO_Practice Data", , , , acFormEdit, acHidden
Forms![PO_Practice Data]!PO_Name.Enabled = True
Forms![PO_Practice Data]!PO_Name.Locked = False
Forms![PO_Practice Data]!Practice_Name.Enabled = True
Forms![PO_Practice Data]!Practice_Name.Locked = False
[code]...
I have the following that I found in a post on Keypress of a text field to limit the field to only numbers. This works great only I need to disallow the entry of zero.
If KeyAscii <> 8 Then ' Not Backspace (important for error correction)
If KeyAscii < 48 Or KeyAscii > 57 Then 'Not a number
Beep 'Let the user know they hit an illegal key
KeyAscii = 0 'Don't let the keystroke through
End If
End If
Hi!
I have a Question about validation rules. I have a table with a field where the values can either be 3 numbers (like 321,245) or 4numbers separated by . (like 321.4). Other employees update these fields so it is importatant that they can't put in text etc.
In the field for validationrule I put the text (Select Distinct [fieldname] from table) but that did not work. Do anybody know an easy way to set the validation rule?
Thanks :eek:
I am trying to validate a text field (named Customer_Surname) and i want to make it so that only letters can be entered into the field and no other numbers or symbols. Is there any way this vlaidation can be done and if so, how?
Cheers
I have one case about validation in the form
example: I have entry in table this mention below:
No.Register | Code_machine
________________________
001 | X01
002 | X01
001 | X02
003 | X02
003 | X01
002 | X03
How to make validation for this case when I will submit the data 001 and X01, the system will be cancel and show warning message : "Data Duplicate!".and of course with this happen, the user will be know what they will submit, it have been submit into table before by other user. if I will do make with one validation like noregister as checking data and use the DLookup, this is no problem.
I've tried to steal an SQL Postcode validator (This is for UK postcodes) and add it to an AfterUpdate event on a field in MS Access. It doesn't work, obviously,The VBA code is:
Private Sub Postal_Code_AfterUpdate()
Dim CHECK_Code As Integer
Dim LResponse As Integer
If InStr("[A-Z][0-9] [0-9][A-Z][A-Z]", Postal_Code) = 0 Then
CHECK_Code = 0
[code]....
Also, how would I put the Check_Code value into the Message box to see what it's bringing back?
Hi there!
I wonder if someone can help me please? I have an Access 2000 database used to record the daily treatments received by patients in our Intensive Care Unit. The database consists of 2 tables;
Table 1 has these fields; [First Name], [Surname], [Hospital Number], [ICU Admission Number] (Primary Key), [Date of admission], [Date of discharge].
Table 2 has these fields; [Date], [ICU Admission number], and various treatment fields requiring a true or false response.
The tables are linked through the [ICU Admission Number] field.
I enter data in the first instance through Table 1 and then click on the '+' in the far left hand column to access Table 2 for each record (Patient), whereupon I enter the daily treatments - each record in this table accounting for 1 day on the unit (i.e. there must be no duplicate values).
When I open Table 2 I need three things to happen to try and avoid mistakes being made.
(1) The first record in the [Date] field must only be equal to the [Date of admission] in Table 1. It must not be possible to enter anything else
(2) In subsequent records in Table 2 the date must increase by one day until it equals the [Date of discharge] in Table 1.
(3) Once this value has been reached it must not be possible to enter subsequent dates or duplicate dates.
If anybody can help me with this query I would be delighted to hear from you. I have tried fiddling around with Validation rules but have had no luck.
If you can help then that would be fantastic.
Best regards
Usr33t
I am trying to validate data in a table.
I have two fields, status and completion date.
What I want is the following:
If [status] field = "Complete" then [completion date] cannot be null.
I don't know if doing this in a table of the form is best using the forms Before Update Event, but I am having trouble figuring how to write it using the expression builder.
Can anyone help or offer suggestions?
I have a table embedded in a form that data is entered on. The data to be entered is a project number, date, and a numerical value. I want the date to be entered only be on a Sunday. Is there a data validation rule to apply or do I need to use VBA? I do not know VBA!
View 3 Replies View RelatedHello,
I am want to validate the data in a table column as per the data in a corresponding column in teh same table.
Ex. I have a table with column "Frequency" of datatype Text.
And other 12column are in the name of the months. i.e. Jan, Feb etc of datatype "Yes/No" in checkbox format. Default value as false.
I have only 4 different values i.e. Yearly, Half Yearly, Quarterly And Monthly.
If the value is Yealy then I should able to change the value on Only "Jan" from False to True.
Similarly If the value is Yearly then I should able to change the value on Only "Jan" & "July" from False to True.
Same holds true for Quarterly changing the values only of March, June, Sep & Dec from false to true.
Can anyone guide me to do this would be great.
Thanks
Sudhir
:(:(:confused:
Hi,
I am using the following validation code for the part number field on one of my forms:
DLookUp("[Door Part Number]","2-MAIN DOOR PART DATABASE","[Door Part Number] = '" & [Door_Part_Number] & "'") Is Null And Not ""
The purpose of this is to prevent users from changing/creating parts with a number that already exists in the database (and the last bit prevents no part number being entered).
It is fine for most situations except 1. If the user changes a part number, then changes it back to the original number again, the validation rule thinks this already exists and forces the user to give another part number.
Can anyone suggest how to get around this problem? It is hopefully very simple, but I can't get my head round how to do it!
Many thanks in advance!!
John
I'm making a student report card. Teachers enter data and then I print them all.
Sometimes data is missed in a field or it's deliberately left empty becasue the data doesn't apply to that student.
I'd like to generate a rpt that shows empty fields. Basically, I'd like a list of student names and the field names that are empty/null so that I can approach teachers and ask them if it was deliberate on not before I print. With 100 or so fields, I can't seem to nut out a query to make it all work.
Any ideas??
Hi - I have an inventory management database allowing stock to be moved between various subinventories. The user choose a transaction type and then details which goods to move. However at the moment they could enter a Quantity that is greater than that available in that subinventory.
So I have a query that gives me:
Part#
Subinventory
OnHandQty
The data entry form has a control source directly to the Inventory Table. I want to compare a text field [Qty] on a new inventory transaction (the person already having selected Part# / SubInventory from combo boxes) to the On Hand Qty.
I have tried Expression Builder in the Field Validation Property and I have tried some sql code on the AfterUpdate of the text box. I'm just not getting it.
Any help appreciated.
Cheers,
Darren
I am an absolute beginner and urgently need help with a validation rule. I need to know how to set a rule to set a minimum and maximum length for a text field record. I want minimum to be 4 and maximum to be 15 (I know I can set a max field size and set to not null but not sure how to make a minimum validation rule.
I am a teacher (not ICT!) having to cover for a sick colleague and students have asked me how to do this and although I am working my way through many of the great learning resources you link to here I have not yet worked out how to do this.
Would really appreciate any help you can give me so I can do my best by the kids.
J
I have a lookup which selects a 'Recipient'.
I need to add a check to see if this 'Recipient' (user selected) already exists within another table.
If so, I need a pop-up to appear.
If not, I want the user to continue unimpeded.
I have a field that looks up the JobType using a LookUp Combobox from another table where these records for JobType will never change.
I want the user to only be able to select from the Combobox for the job type they want and be able to type the beggining of the job type so that the desired job will pop up. Now, i need the field to not be able to accept any other data than what is in the LookUp, so that they cannot enter false values. Duplicates of jobtypes are possible so a primary key cant be used.
Any help guys?
-thanks
I have a button on a form that when I press it, I want it to validate a user's Windows Login ID in a text box on the current form against a table before allowing them access to a form.
If the Login ID in the text box does not match any value in the table I have defined, I wanted a MsgBox displayed saying invalid credentials. Of course if the ID exists in the table, I'd like it to open the next form.
How to define Order that starts with a dependency on the existing value.
Basically, a function that chooses what Status Validation to run then knows when to stop that displays some very simple predictive Inference.
Each Record has a Status. The Status will generally be correct 85% of the time. Once in a while, various things in the database are updated that triggers the business need to change the status.
-A collection of Rule based validation functions matches each Status.
-The objective is not to run Rule 1 through 40 sequentially for each record.
-Each Rule Validation function is lengthy and can take 0.1 seconds per rule (per record).
-If the current record's rule is still valid 85% of the time, Then run that Status Rule Validation function first.
-If the Validation returns True, there is no need to run the rest of the rules. Move to the next record.
The challenge: Statistically, if the Current Status failes its Rule Validation, there is a high probability that one of the Status Validation Function near to the current Status will validate to true.
Like the board game Clue, once a Validation Rule comes out False, there is no need to check it for that single record again.
In an extremely simplistic world, think about Status of : Order in Progress, Order Completed, Completed Order Paid, Shipping in Progress, Item Shipped Ready, Shipped, In Transit, Delivered, Rejected, Payment Recended, ...
So, if the current status was In Transit, there is a higher odd that Delivered would be the next. There would be no need to start from the beginning again. The wonderful world of Metadata.