PC Review


Reply
Thread Tools Rate Thread

Code for running query and results

 
 
=?Utf-8?B?S2F0aGVyaW5l?=
Guest
Posts: n/a
 
      31st May 2004
I'm completely new to coding in VB and I'm making a database. I am starting to pick up a few things and am hoping someone can teach me something new here

I have a text box in which the date is entered after it has been picked on a drop down calendar. Before the user moves off from the date text box, I want to runa query that checks if the date entered is a valid date by comparing it to a table of invalid dates. If it finds a match in the query, I want to code it so that an error box pops up and says "Invalid date, pick another" and, if the query produces no matches, I want the user to just be able to continue entering the record as per usual. Please help :

 
Reply With Quote
 
 
 
 
Wayne Morgan
Guest
Posts: n/a
 
      31st May 2004
You could use the DCount function for this. If it returns 1 or more, the
date is invalid. In the control's BeforeUpdate event, try the following:

If DCount("[DateField]", "[TableName]", "[DateField]=#" & Me.txtDateTextBox
& "#") >= 1 Then
MsgBox "Invalid Date"
Cancel = True
Me.txtDateTextBox .SelStart = 0
Me.txtDateTextBox .SelLength = Len(Me.txtDateTextBox .Text)
End If

The last 2 lines just cause the invalid date to be highlighted so that the
user doesn't have to delete it before they can enter another date. The
brackets [] aren't necessary unless there are spaces in the names or a
reserved word is used for the name, but they shouldn't hurt anything if you
use them anyway.

--
Wayne Morgan
MS Access MVP


"Katherine" <(E-Mail Removed)> wrote in message
news:21D22273-158A-4DF8-BD38-(E-Mail Removed)...
> I'm completely new to coding in VB and I'm making a database. I am

starting to pick up a few things and am hoping someone can teach me
something new here.
>
> I have a text box in which the date is entered after it has been picked on

a drop down calendar. Before the user moves off from the date text box, I
want to runa query that checks if the date entered is a valid date by
comparing it to a table of invalid dates. If it finds a match in the query,
I want to code it so that an error box pops up and says "Invalid date, pick
another" and, if the query produces no matches, I want the user to just be
able to continue entering the record as per usual. Please help
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run query based on results of previous query using code H J Microsoft Access Queries 4 8th Jun 2009 10:51 PM
Running a Query produces no results =?Utf-8?B?V2F5bmUgVmlsZXM=?= Microsoft Access Queries 2 6th Apr 2006 11:36 AM
Code for running query and results =?Utf-8?B?S2F0aGVyaW5l?= Microsoft Access 2 31st May 2004 01:21 PM
Stepping through code gives different results than running it! Simon White Microsoft Excel Programming 2 13th Nov 2003 09:44 PM
Determine whether a query returns results or not (before running it) John Sway Microsoft Dot NET 1 30th Aug 2003 07:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:21 AM.