HI guys,
I have a head scratcher here and i need a little help. if you have a few mins i would really appreciate your help.
I have a small DB that stores 4 fields only ( its a test database so i can understand the concept )
its about hire cars and when they were hired.
it holds
Date the car was hired – [Hire on]
date car was returned – [Hire Off]
Registration number of car – [Reg]
Name of hirer – [Name]
what I’m trying to do is look for duplicate and overlapping hire( this is where the same car has been hired out at the same time - which should be impossible - i.e. Car reg AB1 1AA was hired on 01/02/10 to 10/02/10 to a Mr smith and hired to a Mrs. price on 09/02/10 to 20/02/10. You can see it has over lapped.
What i have is a simple form which allows you to enter a new case. then i have a button which goes into the DB and checks to see if there is any over lapping hire. I have used code to do this on the button click event. When the buttin is pressed it will open a new form which shows you all of the other hires which overlap the one you have open.
the code is : ( sorry about it's rubbish code, i am self taught and new to this )
Private Sub Command9_Click()
On Error GoTo Err_Command9_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim RegMatch As String
Dim MIDDLE As String
Dim EITHER As String
Dim Before As String
Dim After As String
stDocName = "dupes"
RegMatch = "[Reg]=" & "'" & Me![Reg] & "'"
MIDDLE = "(([Find duplicates for main].[hire on]>#" & Me.hire_on & "# and [Find duplicates for main].[hire off]<#" & Me.hire_off & "#))"
EITHER = "(([Find duplicates for main].[hire on]<#" & Me.hire_on & "# and [Find duplicates for main].[hire off]>#" & Me.hire_off & "#))"
Before = "(([Find duplicates for main].[hire on]<#" & Me.hire_on & "# and [Find duplicates for main].[hire off]<#" & Me.hire_off & "#and [Find duplicates for main].[hire off]>#" & Me.hire_on & "#))"
After = "(([Find duplicates for main].[hire on]>#" & Me.hire_on & "# and [Find duplicates for main].[hire off]>#" & Me.hire_off & "# and [Find duplicates for main].[hire on]<#" & Me.hire_off & "#))"
stLinkCriteria = RegMatch & " and (" & MIDDLE & " or " & EITHER & " or " & Before & " or " & After & ")"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_Command9_Click:
Exit Sub
Err_Command9_Click:
MsgBox Err.Description
Resume Exit_Command9_Click
End Sub
This code adds this to the form filter : ( this is what it looks like formatted when returning a result to the filter on the new form which shows the duplciates.
[Reg]='123456' and
((([Find duplicates for main].[hire on]>#01/01/2001#
and
[Find duplicates for main].[hire off]<#10/01/2001#))
or
(([Find duplicates for main].[hire on]<#01/01/2001#
and
[Find duplicates for main].[hire off]>#10/01/2001#))
or
(([Find duplicates for main].[hire on]<#01/01/2001#
and
[Find duplicates for main].[hire off]<#10/01/2001#
and
[Find duplicates for main].[hire off]>#01/01/2001#))
Or
(([Find duplicates for main].[hire on]>#01/01/2001#
and
[Find duplicates for main].[hire off]>#10/01/2001#
and
[Find duplicates for main].[hire on]<#10/01/2001#)))
Pretty sure it has something to do with the way I am bracketing it up with the "and" and "or" statements – but I cant figure it out. Is it something obvious I am missing >?
there is a possiblulity i am going about this all wrong - as i say, i am new to this. But if i can just get the filter working then it will suit needs perfectly.
fingers crossed
I have a head scratcher here and i need a little help. if you have a few mins i would really appreciate your help.
I have a small DB that stores 4 fields only ( its a test database so i can understand the concept )
its about hire cars and when they were hired.
it holds
Date the car was hired – [Hire on]
date car was returned – [Hire Off]
Registration number of car – [Reg]
Name of hirer – [Name]
what I’m trying to do is look for duplicate and overlapping hire( this is where the same car has been hired out at the same time - which should be impossible - i.e. Car reg AB1 1AA was hired on 01/02/10 to 10/02/10 to a Mr smith and hired to a Mrs. price on 09/02/10 to 20/02/10. You can see it has over lapped.
What i have is a simple form which allows you to enter a new case. then i have a button which goes into the DB and checks to see if there is any over lapping hire. I have used code to do this on the button click event. When the buttin is pressed it will open a new form which shows you all of the other hires which overlap the one you have open.
the code is : ( sorry about it's rubbish code, i am self taught and new to this )
Private Sub Command9_Click()
On Error GoTo Err_Command9_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim RegMatch As String
Dim MIDDLE As String
Dim EITHER As String
Dim Before As String
Dim After As String
stDocName = "dupes"
RegMatch = "[Reg]=" & "'" & Me![Reg] & "'"
MIDDLE = "(([Find duplicates for main].[hire on]>#" & Me.hire_on & "# and [Find duplicates for main].[hire off]<#" & Me.hire_off & "#))"
EITHER = "(([Find duplicates for main].[hire on]<#" & Me.hire_on & "# and [Find duplicates for main].[hire off]>#" & Me.hire_off & "#))"
Before = "(([Find duplicates for main].[hire on]<#" & Me.hire_on & "# and [Find duplicates for main].[hire off]<#" & Me.hire_off & "#and [Find duplicates for main].[hire off]>#" & Me.hire_on & "#))"
After = "(([Find duplicates for main].[hire on]>#" & Me.hire_on & "# and [Find duplicates for main].[hire off]>#" & Me.hire_off & "# and [Find duplicates for main].[hire on]<#" & Me.hire_off & "#))"
stLinkCriteria = RegMatch & " and (" & MIDDLE & " or " & EITHER & " or " & Before & " or " & After & ")"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_Command9_Click:
Exit Sub
Err_Command9_Click:
MsgBox Err.Description
Resume Exit_Command9_Click
End Sub
This code adds this to the form filter : ( this is what it looks like formatted when returning a result to the filter on the new form which shows the duplciates.
[Reg]='123456' and
((([Find duplicates for main].[hire on]>#01/01/2001#
and
[Find duplicates for main].[hire off]<#10/01/2001#))
or
(([Find duplicates for main].[hire on]<#01/01/2001#
and
[Find duplicates for main].[hire off]>#10/01/2001#))
or
(([Find duplicates for main].[hire on]<#01/01/2001#
and
[Find duplicates for main].[hire off]<#10/01/2001#
and
[Find duplicates for main].[hire off]>#01/01/2001#))
Or
(([Find duplicates for main].[hire on]>#01/01/2001#
and
[Find duplicates for main].[hire off]>#10/01/2001#
and
[Find duplicates for main].[hire on]<#10/01/2001#)))
Pretty sure it has something to do with the way I am bracketing it up with the "and" and "or" statements – but I cant figure it out. Is it something obvious I am missing >?
there is a possiblulity i am going about this all wrong - as i say, i am new to this. But if i can just get the filter working then it will suit needs perfectly.
fingers crossed