Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weird problem in dlookup

Status
Not open for further replies.

Spikemannen

Instructor
Feb 22, 2005
58
0
0
SE
Hi!

I have tried this code in both access 2000 and access xp.
In access 2000 this works, but not in access xp?!
How should I do this to get it to work in access xp?

Problem:
I have a form where I name an object and choose between which two dates it is avaible in the form frmObject.
In my second form, frmBooking, I will choose between which two dates I want the object.
The dates has to be between the two avaible dates for the object in frmObject. When there is another persone who wants to book the object he/she shouldn't be able too book the object when I have booked it.
My code looks like this:

Code:
Private Sub txtArrival_AfterUpdate()

Dim strObject As String
Dim strFromdate As String
Dim strAvFromDate As String
Dim strAvToDate As String
Dim strBookFromDate As String
Dim strBookToDate As String

strObject = Form_frmBooking.cboObject.Value

If cboObject.Value = False Then
    MsgBox "You have to choose an object.", , "Booking"
    txtArrival.Value = ""
    cboObject.SetFocus
    Exit Sub
End If

If IsDate(txtArrival.Value) = True Then
    strFromdate = txtArrival.Value
Else
    MsgBox "You have to choose a arrival date.", , "Booking"
    Form_frmBooking.txtArrival.Value = ""
    Form_frmBooking.txtArrival.SetFocus
    Exit Sub
End If

strAvFromDate = DLookup("[AvFrom]", "tblObject", "[ObjectID] = " & strObject)
strAvToDate = DLookup("[AvTo]", "tblObject", "[ObjectID] = " & strObject)
strBookFromDate = DLookup("[Arrival]", "tblBooking", "[ObjectID] = " & strObject)
strBookToDate = DLookup("[Departure]", "tblBooking", "[ObjectID] = " & strObject)

If strFromdate <> "" Then
    If strFromdate < strAvFromDate Or strFromdate > strAvToDate Then
        MsgBox "You have to choose a arrival date between the Avaible from and Avaible to dates for the object you have choosen.", , "Booking"
        Form_frmBooking.txtArrival.Value = ""
        Form_frmBooking.txtArrival.SetFocus
        Exit Sub
    End If
    If strFromdate <= strBookToDate And strFromdate >= strBookFromDate Then
        MsgBox "You can not book this date because you have another booking at this time for the selected object", , "Booking"
        Form_frmBooking.txtArrival.Value = ""
        Form_frmBooking.txtArrival.SetFocus
        Exit Sub
    End If
End If

End Sub

So what will I do? Please help me...

Best Regardz,

Spikemannen
 
I'd suggest to use Date variables instead of String.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top