My table is defined as follows :
Reference text Primary Key
StartDate date Primary Key
EndDate date can be null
I currently have a row with :
Reference = ABC,
StartDate = 1st Jan 2009, and
EndDate = 1st November 2009.
I want my Form to allow me to enter a 2nd row with
Reference = ABC, and
StartDate greater than or equal to the EndDate above.
If I enter an EndDate prior to this, then I want to display a meaningful message.
This should be the case for all References, not just ABC.
Should I do so as a Validation Rule in the table design
Or an ‘on enter’ event in the Form design ?
And what would the coding look like ?
Many thanks
8 1598
I think I would use the BeforeUpdate event of the form, and check the entered date against a - DLookup("StartDate", "myTable", "Reference = """ & Reference & """")
NeoPa 32,556
Expert Mod 16PB @grinder332518
I would assume you actually mean StartDate.
With that basic assumption, and that the controls on your form are named as the fields are in the table, then you want something like the following in your Form_BeforeUpdate() event procedure : - Dim datMax As Date
-
-
datMax = DMax("[EndDate]", _
-
"[YourTable]", _
-
"[Reference]='" & Me.Reference & "'")
-
If Me.StartDate < datMax Then
-
Call MsgBox("Your failure message here")
-
Cancel = True
-
Exit Sub
-
End If
Thanks NeoPa.
As you gathered, I did mean StartDate.
Your suggestion works beautifully.... as far as it goes.
However, I simplified my example when posting.
The field “Ref” should actually be 2 separate fields : “Ref1” and “Ref2”.
I have tried to enhance your coding by altering the 3rd argument : - "[Ref1]='" & Me.Ref1 & "'" , "[Ref2]='" & Me.Ref2 & "'")
but cannot get the syntax correct.
Can you assist again please ?
Many thanks.
NeoPa 32,556
Expert Mod 16PB
You're nearly there. You have to use "AND" between the two items : - "[Ref1]='" & Me.Ref1 & "' AND [Ref2]='" & Me.Ref2 & "'")
The syntax is identical to the WHERE clause in SQL except without the keyword WHERE, if that helps.
Although it's rarely necessary, I usually put parentheses around separate items thus : - "([Ref1]='" & Me.Ref1 & "') AND " & _
-
"([Ref2]='" & Me.Ref2 & "')")
Thanks NeoPa
I should have mentioned that Ref2 is defined as a number, not text.
Will this effect the coding ?
Also, when I create a new Ref1 / Ref2 combination, there is no existing EndDate for a previous row. Will the code still allow me to enter a StartDate ?
Many thanks for your continuing support.
Excuse me, but do you ever plan on giving us all the facts here? Posting a problem, and when it's answered, saying "Oh, but that's not all" and when that's answered saying "Oh, but that's not all" and repeating this four times is simply not acceptable!
State your problem, in full, when you originate your post!
Linq ;0)> NeoPa 32,556
Expert Mod 16PB
As Linq says, it is only considerate to give a bit more thought to your question before posting it. It may be tedious, but if not doing so causes those trying to help you to spend extra time, fundamentally unnecessarily, on your problems, then this should be seen in the context of asking a favour. We're happy to put in the time if it's for something you're struggling with, but less happy to spend our time simply to save you the effort of preparing your question properly.
I appreciate your first effort was an attempt to be quick and not unduly complicated, which is a good thing. I'd just request, much as Linq did, that you prepare a little more carefully to avoid unnecessary time wastage.
Moving on now to the question. @grinder332518
Yes. Definitely.
The single-quotes will not be required for numeric literals. They are only required for strings. See Quotes (') and Double-Quotes (") - Where and When to use them & Literal DateTimes and Their Delimiters (#) for the full explanation. @grinder332518
This is a scenario I hadn't coded for. Such a situation would crash the code as it now stands. Try instead, something like : - Dim datMax As Date
-
-
datMax = Nz(DMax("[EndDate]", _
-
"[YourTable]", _
-
"[Ref1]='" & Me.Ref1 & "' AND " & _
-
"[Ref2]=" & Me.Ref2), #1/1/1900#)
-
If Me.StartDate < datMax Then
-
Call MsgBox("Your failure message here")
-
Cancel = True
-
Exit Sub
-
End If
many thanks for your help.
the code is working fine now.
I'll be more specific in future.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: AnnMarie |
last post by:
<script language="JavaScript" type="text/javascript">
<!--
function validate(theForm)
{
var validity = true; // assume valid
if(frmComments.name.value=='' && validity == true)
{
alert('Your...
|
by: Dale |
last post by:
Hi Everyone,
I've got a form that provides a pop-up calendar for users to select
dates for requesting jobs to be completed. The calendar works great,
but it unfortunately allows users to select...
|
by: Dr John Stockton |
last post by:
It has appeared that ancient sources give a method for Numeric Date
Validation that involves numerous tests to determine month length;
versions are often posted by incomers here. That sort of code...
|
by: Steve Wright |
last post by:
I am trying to validate if an entry on a form is a date.
I have adapted code I found here
http://www.codingforums.com/archive/index.php/t-14325 as below but I can't
seem the get the results that I...
|
by: Ash |
last post by:
Hi everyone,
This problem has been puzzling me for a fair time now, and has severely
frustrated me!! Perhaps I'm just not getting the syntax right, but the
problem is rather simple...
Take a...
|
by: Vi |
last post by:
Hi,
I have a form which displays some orders based on dates selected or based on
an order number. I have two different buttons for each kind of query, but
both buttons call the same method in the...
|
by: JIM.H. |
last post by:
Hello,
I have this validation expression:
^(?:(?:0?|1)|(?:0?|11)(?!\/31)|(?:0?2)(?:(?!\/3|\/29\/(?:(?:0||)00|(?:\d{2}(?:0||))))))\/(?:0?||3)\/\d{4}$
This is supposed to match MM/DD/YYYY it is...
|
by: panjap |
last post by:
Hello
i have had problems with validation with dates, as i find this difficult to insert into my coursework on a shop and ordering goods.
Heloo everyone, i am currently struggling on how to...
|
by: mshroom12 |
last post by:
I am having trouble with the following project on hand. I use Eclipse to do my work in Java. This is what I'm supposed to complete.
Date Validation
In this exercise you will write a program...
|
by: maz77 |
last post by:
I'm trying to develop a good validation for a date in C#; a valid date
can be inserted in these formats:
- dd/mm/yyyy
- dd/mm/yyyy h24:m
- mm/dd/yyyy
- mm/dd/yyyy h12:m
How can I proceed?
Is...
|
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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: 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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
| |