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 9th, 2005, 02:13 PM
Registered User
 
Join Date: Mar 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Access Form problem, date comparison

Anyone who can help me out,

What I have is a form that has five combo boxes, Customer, Resource Type, Patch, StartDate, and EndDate. On the form I select a Customer, a Resource Type, a Patch, a StartDate and an EndDate. I then have a SaveRecord Command Button. The On Click function is as follows:


Private Sub cmdSaveRecord_Click()
  Dim strWhere As String
  Dim stDocName As String
  Dim stLinkCriteria As String
  Dim cmdSave As String
  Dim Patch As String
  Dim ResourceType As String
  stDocName = "frmScheduleResource"
  stLinkCriteria = "[cmdSaveRecord]=" & "" & cmdSaveRecord & ""
  Resourcetype = "qryScheduledResourceType.Resource Type"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
  If IsNull(Me.Patch) Then
    MsgBox "You must specify a Patch."
    Exit Sub
  Else
    strWhere = "qryScheduledResourceType.Patch = " & Me.Patch
  End If
  If IsNull(Me.ResourceType) Then
    MsgBox "You must specify a Resource Type."
    Exit Sub
  Else
    strWhere = "qryScheduledResourceType.ResourceType = " & Me.ResourceType
  End If
  If IsNull(Me.StartDate) _
    Or (Not IsDate(Me.StartDate)) Then
    MsgBox "You must enter a start date."
    Exit Sub
  Else
    strWhere = strWhere & _
      " AND EndDate >= #" & Me.StartDate & "#"
  End If
  If IsNull(Me.EndDate) _
    Or (Not IsDate(Me.EndDate)) Then
    MsgBox "You must enter an end date."
    Exit Sub
  Else
    If Me.StartDate > Me.EndDate Then
      MsgBox "Start date cannot be greater than end date."
      Exit Sub
    End If
    strWhere = strWhere & _
      " AND EndDate <= #" & Me.EndDate & "#"
  End If
  DoCmd.OpenForm "frmScheduledResource", WhereCondition:=strWhere

End Sub

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_cmdSaveRecord_Click:
    Exit Sub

Err_cmdSaveRecord_Click:
    MsgBox Err.Description
    Resume Exit_cmdSaveRecord_Click
End Sub



What I want the function to do is On Click:
1. Open a query that has the five fields listed above.
2. Compare the Patch, Resource Type and StartDate, EndDate fields to see if:

a: if Patch = Null, Then an error message box appears.
b: if Resource Type = Null, Then an error message box appears.
c: if StartDate = Null, Then an error message box appears.
d: if EndDate = Null, Then an error message box appears.
e: if StartDate > EndDate, Then an error message box appears.
f: if Patch and Resource Type > 0 and new StartDate and new EndDate = old StartDate and old EndDate, Then an error message box appears. (for example:

CustomerID Patch ResourceTypeID StartDate EndDate
Customer A (1) NO TEST TYPE 1 01-Mar-05 03-Mar-05
Customer B (2) NO TEST TYPE 2 02-Mar-05 04-Mar-05
Customer C (3) NO TEST TYPE 3 03-Mar-05 05-Mar-05
Customer D (4) NO TEST TYPE 4 04-Mar-05 06-Mar-05


In the table above, if I input a new record as follows:

Customer E (1) NO TEST TYPE 1 2-Mar-05 3-Mar-05

I should get an error message, because Patch: (1) NO TEST and ResourceTypeID, TYPE 1 is already being used by Customer A from
1 to 3 March 2005. Customer E should not be able to use this Patch and Resource Type until 4 March, 2005. So I need code that searches dates between the start and end dates)

    f: if Patch and Resource Type = 0, Then perform save record function.

3. Close the query


When I run the code above, I am getting a Compile Error: method or data member not found.

If you or someone knows what I should do, Please help.

Thanks
James Jackson
[email protected]
[email protected]







Similar Threads
Thread Thread Starter Forum Replies Last Post
Date comparison problem mat41 Javascript 3 August 30th, 2006 09:22 PM
date comparison function for a form jackson_jl Access 2 March 9th, 2005 01:28 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
Date Comparison cmiller PHP How-To 3 June 19th, 2003 02:58 PM





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