Trancemission
Technical User
I have a procedure which when clicked should take a date, lookup some values, add a number of days to the date [depeneding on previous lookup] and loop thorugh this for as long as there is data.
My looping all works fine the problem I face is with dates. Access seems to interperate the date as mm/dd/yyyy but all my dates are uk format dd/mm/yyyy. I have tried numerous functions and trying to change the data [as you can see in comments in my code] but to no luck.
I understand that MS access 2000 does all functions using the mm/dd/yyyy format?!?!?
Anyways my code:
Here we set a global date where I want to start from, this will be a input box when done. I try to enter the date as UK but i'm thinking it changes this becasue I have declared this var as a date.
Below is where I get my top level data [the is where I get the number I need to add to the date]
Above is where we should be getting data but as the date is interpred wrong then my results are wrong, you can see the first time it is ran sdate should be my globaldate, I then add on the number of days from the db
When I run the above the dates are inputted in the US format.
I have tried using the format function but I seem to be getting the same problem.
Thanks in advance
Trancemission
=============
If it's logical, it'll work!
My looping all works fine the problem I face is with dates. Access seems to interperate the date as mm/dd/yyyy but all my dates are uk format dd/mm/yyyy. I have tried numerous functions and trying to change the data [as you can see in comments in my code] but to no luck.
I understand that MS access 2000 does all functions using the mm/dd/yyyy format?!?!?
Anyways my code:
Code:
'Declare databases
Dim DbCurr As Database
Set DbCurr = DBEngine.Workspaces(0).Databases(0)
'Open Recordset
Dim dbrs As Recordset
Dim dbRs2 As Recordset
Dim hotelrs As Recordset
Dim total As Currency
Dim anothedate As Date
Dim sdate As Date
Dim edate As Date
Dim gdatE As Date
Dim globaldate As Date
Dim pdate As Date
' Set global dates
globaldate = #12/31/2004#
Code:
You can see where I have been playing
'globaldate = Format(globaldate, "mm / dd / yyyy")
'tmp = Split(globaldate, "/")
'globalukdate = "" & tmp(1) & "/" & tmp(0) & "/" & tmp(2)
'globaldate = globalukdate
Below is where I get my top level data [the is where I get the number I need to add to the date]
Code:
' Now we can attempt to get a final price
Set dbrs = DbCurr.OpenRecordset("SELECT * FROM tbl_multi_centres_detail WHERE (((tbl_multi_centres_detail.MultiCode) = '" & Me.MultiCode & "')) ORDER BY tbl_multi_centres_detail.legorder;")
MsgBox "Number of records: " & dbrs.RecordCount
dbrs.MoveFirst
'Loop thorugh and get price
sdate = globaldate
edate = globaldate + dbrs!NumNights
Do Until dbrs.EOF
Set hotelrs = DbCurr.OpenRecordset("SELECT AllPrices_ww.HName, AllPrices_ww.ExValue, AllPrices_ww.Room_Type, AllPrices_ww.PAX, AllPrices_ww.Sdate, AllPrices_ww.edate, AllPrices_ww.txtCurrency, AllPrices_ww.curCosts, AllPrices_ww.HtCode, AllPrices_ww.MealTxt FROM AllPrices_ww WHERE (((AllPrices_ww.Room_Type)='" & dbrs![HotelRoomType] & "') AND ((AllPrices_ww.PAX)='" & dbrs!HotelPAX & "') AND ((AllPrices_ww.Sdate)<=#" & sdate & "#) AND ((AllPrices_ww.edate)>=#" & sdate & "#) AND ((AllPrices_ww.HtCode)='" & dbrs!HotelCode & "'));")
Above is where we should be getting data but as the date is interpred wrong then my results are wrong, you can see the first time it is ran sdate should be my globaldate, I then add on the number of days from the db
Code:
Do Until hotelrs.EOF
'Lets convert to GBP using the ExRate from the table
exrate = hotelrs!ExValue
' Chech not null
If IsNull(hotelrs![curcosts]) Then
MsgBox "Hotel: " & dbrs!HotelCode & " has no cost associated using 0"
costgbp = 0
Else
costgbp = (hotelrs![curcosts] / exrate) * dbrs!NumNights
End If
DoCmd.SetWarnings (0)
DoCmd.RunSQL "INSERT into tbl_temp_mcgrid (McCode,HotelCode,StartDate,EndDate,CostUKP,NumNights,Occupancy,gstartdate) VALUES ('" & Me.McCode & "','" & dbrs!HotelCode & "',#" & sdate & "#,#" & edate & "#,'" & costgbp & "', '" & dbrs!NumNights & "','" & dbrs!HotelPAX & "', #" & globaldate & "#)"
DoCmd.SetWarnings (1)
When I run the above the dates are inputted in the US format.
Code:
total = total + (costgbp * dbrs!NumNights)
hotelrs.MoveNext
Loop
sdate = edate
edate = sdate + dbrs!NumNights
dbrs.MoveNext
Loop
I have tried using the format function but I seem to be getting the same problem.
Thanks in advance
Trancemission
=============
If it's logical, it'll work!