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

MS Access VBA Code field validation - before update

I'm really , 'REALY' new to vba code... learning on my own. I've successfully written some small stuff on my own, but now need help. I've created a MS Acces user form with two combo boxes. It has several fields 3 of which need to be validated before the user exits (one of them being a combo box).

[OrderRes, [CompDt]and [CompBy]

If the [OrderRes] = “5 DAY LETTER” (ID 16). User should not be able to add a [CompDt] and or [CompBy]

If a user selects a [Order Result] other than “ 5 DAY LETTER” (ID 16), [CompDt] and [CompBy] are required.

If [OrderRes], [CompBy] and [CompDate] are null okay to [exit]

How would I write this code? Can some please provide a example?

This is what I've done thus far... not sure if it will work, but I don't know how to include all the scenarios:

Expand|Select|Wrap|Line Numbers
  1. If IsNull (Me.OrderRes] And IsNull(Me.CompDt) And IsNull(Me.CompBy) then
  2.     DoCmd.Close
  3. ElseIf IsNull(Me.CompDt) = False or IsNull(Me.CompBy) = False then
  4.     If Me.OderRes = “5 DAY LETTER” THEN
  5.         DoCmd.Close
  6.     Else
  7.         MsgBox "Remove Completion updates"
  8.     End If
  9. End If



Thanks in advance for you help,
Anthony
Mar 8 '18 #1
4 1865
twinnyfo
3,653 Expert Mod 2GB
AMarvelFan,

Weclome to Bytes!

Please know that we do want to help you on this forum. However, we typically do not get into the habit of writing solutions for our users. We will gladly troubleshoot irksome code that doesn't execute properly and guide you toward a solution.

That being said, based upon what you have described (including your level of expertise), I want to encourage you that you are much closer to a solution than you might think.

If you know a little bit about VBA, consider these questions:
  1. When would you want to check these data points?
  2. How would one go about checking the validity of the Text Boxes?
  3. What other options might be available for this solution?
Again, I think you are very close (conceptually) to your solution. We will stand available to work through a solution for you--but you must put forth an initial effort of your own.
Mar 8 '18 #2
twinnyfo,

thanks...

This is what I had come up with... not sure if it will even work but.. I don't know how to include one of the scenarios:

Expand|Select|Wrap|Line Numbers
  1. If IsNull (Me.OrderRes] And IsNull(Me.CompDt) And IsNull(Me.CompBy) then
  2.     DoCmd.Close
  3. ElseIf IsNull(Me.CompDt) = False or IsNull(Me.CompBy) = False then
  4.     If Me.OderRes = “5 DAY LETTER” THEN
  5.         DoCmd.Close
  6.     Else
  7.         MsgBox "Remove Completion updates"
  8.     End If
  9. End If
Mar 8 '18 #3
twinnyfo
3,653 Expert Mod 2GB
Anthony,

First, please use the Code tags when entering code (the "[CODE/]" button in your text editor). I also changed the formatting a bit to make it easier to follow and took the liberty of changing the last ElseIf to an End If.

Second, See how close you are to a solution? I can....

The first question is, when do you want to make such checks? You have three fields that can be updated: OrderRes, CompDt and CompBy. What if someone enters CompDt and CompBy and then selects OrderRes of 16? Do you want those other values cleared?

So, will this code execute after a Command Button or after the update of a Text/Combo box?

From a learning perspective, these are the things you will want to consider as you develop your projects.

I also assume that this is a Form with an underlying Table that is being updated, yes?

I might be away from my computer a bit over the next few days, but I (or another user) will try to help you with this....
Mar 8 '18 #4
NeoPa
32,556 Expert Mod 16PB
To follow on from Twinny's good advice I would also warn that using a word processor for code is an easy way to get things wrong. It may be that you only used one in order to post your code here but either way never use a word processor as it can change your important quote (" & ') characters into other ones that look similar but simply don't work. Just as you have in your posted code. The correct ones should always show as vertical. Never as specifically opening or closing quotes of any form.
Mar 16 '18 #5

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

Similar topics

1
by: Martin Nadoll | last post by:
Hello, i have a few problems with form field validation: First i have to check, wether a field is filled with 10 integer numbers. Also allowed is " " and "-" but no letters, and the input of ...
2
by: Doslil | last post by:
I am trying to validate the fields in my database.I have already validated the fields to check for not null.Here is what I have written for Numeric and text field. Private Function EENUM() On...
6
by: Matt | last post by:
I'm having difficulty with trying to update a Access memo field through an SQL statement where the value I'm trying to pass is longer than 255 characters. The field is being truncated. I'm using...
1
by: WJ | last post by:
My users want to display the text value of all the "Required Field Validation controls" at all time , so I set them all to "Static" but they donot showup until the submit button is pressed. And...
3
by: Randy Smith | last post by:
Hi, It appears as though we will have a new coding standard for field validation that includes "IsPageValid". I've been unable to find anything about this on the "microsoft.com" site by googling...
12
by: jayjayplane | last post by:
Thanks everybody here answered my last data field validation question about the alert of future date. Here I get another question, sorry, I am really an Access newbie... The question is : I...
1
by: m115435 | last post by:
We are using an Access database developed by an outside vendor in 2001-2003. When entering data, the user would click OK on the form and a BeforeUpdate module would run to make sure entries had...
1
by: whitleys | last post by:
Imported Excel table of 60 Employees into new Access table "Employees". Two Fields 8 positions 25 positions. Created "Transaction" table and want to validate field in "Transactions" to field in...
13
by: dfrost | last post by:
In MS Access 2007, I am having difficulty with the syntax for a field validation using a date range for current year. For example, >= #1/1/2013# And <#1/1/2014# will prevent users from entering a...
2
by: veeru8989 | last post by:
Hi, I created a form using form wizard and placed a UPDATE button. and written code CurrentDb.Execute "UPDATE tblQuotation SET tblQuotation.ItemCategory =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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
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
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.