View Full Version : If then does not compute


philips44
10-12-2008, 09:19 AM
hello,
I'm trying to build a hotel automation application and got stuck with the the reservation part as follows: there are two combo boxes in a form followed by a code to determine the price from a table. However I get no match whatsoever even though I have displays values from both form and table side. I believe that my IF cycle is not working properly and appreciate any help.

Note: I have tried If ... then... else and keep getting error also I need to repeat the If's for Double, Triple, Suite, etc.. room types.


Thank you





Private Sub Combo50_AfterUpdate()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim isValid As Boolean
Set db = Access.Application.CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM seasons ", dbOpenDynaset)


' >>>>>>>>>>>>>>> check if both dates are not null <<<<<<<<<<<<<<<<<<<<<<<
If Not (IsDate(arrivaldate)) Then Exit Sub
If Not (IsDate(cikistarihi)) Then Exit Sub
' >>>>>>>>>>>>>>> open table and start comparing >>>>>>>>>>>>>>>>>>>>>>>>>

With rst
.MoveLast
.MoveFirst

Do While .EOF = False

If rst!tourname = Form![Combo50] And Form![Text59] = "Single" And arrivaldate > rst!season1startdate And _
checkoutdate < rst!season1enddate And arrivaldate > rst!season1startdate And checkoutdate < rst!season1enddate Then
nightprice = rst!season1singleprice & MsgBox("case 1 true")

End If


If rst!tourname = Form![Combo50] And Form![Text59] = "Single" And arrivaledate > rst!season2startdate And _
chekoutdate < rst!season1enddate And giristarihi > rst!season2startdate And checkoutdate < rst!season2enddate Then
nightprice = rst!season2singleprice And MsgBox("case 2 true")

End If


If rst!tourname = Form![Combo50] And Form![Text59] = "Single" And arrivaldate > rst!season2startdate And _
checkoutdate < rst!season1enddate And arrivaldate > rst!season3startdate And cikistarihi < rst!season3enddate Then
nightprice = rst!season3singleprice And MsgBox("case 3 true")

End If
MsgBox (rst!tourname)
.MoveNext
Loop
End With
Set rst = Nothing
Set db = Nothing
End Sub

jal
10-12-2008, 10:44 AM
I don't understand your code because I've never used an AND before a MsgBox invocation. You wrote:


And MsgBox("case 3 true")


Is that valid?

philips44
10-12-2008, 11:13 AM
True and may be omitted

jal
10-12-2008, 12:52 PM
Stlll not working?

By the way, if you decide you want to use Else If, make sure to type it in as one word:

ElseIF



Otherwise, all I can suggest is that you break it down into small pieces, testing each condition and attempting to detect which conditions are failing the tests. In other words find out which IF-Then conditions are showing up as false, and which as true. I know it's tedious, but it may be the sure-fire way to go.