Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 7th, 2005, 03:05 PM
Registered User
 
Join Date: Mar 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help programing code for date comparison

I am working on a database project that needs to utilize date comparison code. I could really use some help on this one. Heres the problem below..



Problem:



I need to construct code that compares data in three fields: Assets, StartDate, and EndDate. I have a database that I want to be able to schedule the use of assets for customers from a start date to and end date. Once an asset is scheduled for a customer from the start date, it cannot be used for another customer until after the end date. If an asset is already scheduled, then an error message box will appear on my form, or if the end date is before the start date an error message box will appear.(Sort of like Library Book code that allows the check out and return date of a book where no one else can check the book out until it is returned by the customer) If there is anyone out there who knows of code that I can use to program a form button on my Access 2003 database project please help. I have tried to write it out below in this form:


On Click
1. Opens qryScheduledResourceType
2. Compares Resource Type with StartDate and EndDate.
3. If there is no conflict with the Resource Type and dates, Then a new record
                Will be saved.
4. If not, an error message will occur because either resources are already scheduled with the new dates or the end date preceeds the startdate.



I have started to try to write code for this, however I know that I am missing quite a few pieces:

Private Sub CommandSave_Click()
DoCmd.OpenQuery qryScheduleResourceType, acPreview

If ResourceType = 0 Then
Perform Save Function
ElseIf ResourceType > 0, Where StartDate (New) = between StartDate (Old) and EndDate (Old)Then
MsgBox "Scheduling Error-Resource Type Already Scheduled. Pick Another Resource Type or other Dates"
ElseIf EndDate < StartDate Then
MsgBox "End Date Error - End Date Occurs Before Start Date"
End If
End Function



I know this is crude, but it is the only way that I can come up with to explain this. I wish to tie this code, if possible to a Save record button on my form that will run this test, and either input the new record, or will produce an error message telling the customer to reschedule either another asset or dates. If you know how I can do this, I would really appreciate the help. I can be reached by reply to this email or the mail and phone number address below.

Thanks in advance.

James Jackson
813-828-4628
[email protected]







Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Comparison jroxit Classic ASP Databases 5 October 5th, 2007 05:39 PM
How to add Value Programing to an HTML code (Sum) Deekay HTML Code Clinic 2 April 1st, 2005 02:28 PM
Date Comparison Code Needed jackson_jl Beginning VB 6 0 March 14th, 2005 12:16 PM
Date comparison rajuru Beginning PHP 2 February 19th, 2005 10:33 AM
Date Comparison hoffmann Classic ASP Databases 7 October 21st, 2004 09:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.