|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello Everyone,
I need some help to start off with this !!! I am trying to figure out how to create a sub that checks into Date Fields. Let's say I have two tables: tblApt (where I store the name of the properties) and tblAvail (the availability table) for the tblApt I only have IDApt and txtName and for tblAvail only IDAvail, dtArrival, dtDeparture and IDApt (to relate it to the tblApt) to make sure that each apartment has its own availability. How do I check in the availability table if a certain date has been already taken? Thanks for your time. |
|
#2
|
|||
|
|||
|
Hi ItalianLodging
Try this to see if it will get what you are looking for: Dim db As DAO.Database Dim rs As DAO.Recordset Dim dteRequest As Date Dim strSQL As String Dim i As Integer dteRequest = RequestedDate strSQL = "Select [dtArrival], [dtDeparture] FROM tblAvail " strSQL = strSQL & "WHERE [dtArrival] >= #" & dteRequest & "#" strSQL = strSQL & " OR [dtDeparture] <= #" & dteRequest & "#" Set db = CurrentDb Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot) rs.MoveLast i = rs.RecordCount If i > 0 Then Msgbox "Room is Taken" Else Msgbox "Room is Available" End If This should give you some ideas on how to rewrite the code into your application. lwells |
|
#3
|
|||
|
|||
|
Further Help
Hello Dear Iwells,
first thank for your prompt help. Unfortunately I am too much a newbie and with this approach I am getting a little disoriented. I have tried to get out as much as I could from your script but I am not getting where I want (My fault I am sure). I beg you for a bit of extra help. What I want to achieve is to create the Sub that checks into the date fields already stored in my table. I was thinking to something like Private Sub Form_BeforeUpdate(Cancel As Integer) If Me.NewRecord = True Then Dim dtRequest As Date, strMessage As String strMessage = " Date Already Entered " if dtRequest = "#" & dteRequest & "#" = "#" & dteRequest & "#" then MsgBox strMessage, vbInformation Cancel = True DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo Exit Sub End If Me.RecordsetClone.MoveFirst Me.RecordsetClone.FindFirst dtRequest Do Until Me.RecordsetClone.NoMatch Me.RecordsetClone.FindNext strWhere Loop End If End Sub I have tried to work with your script but I couldn’t make it controlling the data field. It gives me the msgBox with room taken even if I leave the date blank and move onto the next record. I have attached the DB in zip file I hope you can look at it. Thanks L. Quote:
|
|
#4
|
|||
|
|||
|
Hi ItalianLodging
See if this is closer to what you were looking for. Cheers lwells |
|
#5
|
|||
|
|||
|
Hello Iwells,
the function works perfectly but there is one thing that I was trying to solve on my own but I am still getting lost so here I am begging for extra help. If I insert a reservation starting 10/10/2005 end ending 15/10/2005 for an x Apt and right after I insert for example another one for the same apt starting 12/10/2005 and ending 16/10/2005 the control works perfectly on the date 12/10/2005 because it is already taken and displays the message. This is great but if I, on the same apt, insert the following reservation starting 11/10/2005 and ending 17/10/2005 the reservation get accepted fine while the period is taken and only the single nights of 11/10 and 17/10 are available NOT the period in between 12 - 16. What do you think the best way to make a control over all the dates present in the RS? Quote:
|
|
#6
|
|||
|
|||
|
Hi ItalianLodging
Yeah, didn't have the code to check for dates that were already booked. Add this additional piece of code to your Function CheckDeparture() Dim dteRequest1 As Date dteRequest1 = dtArrival.Value Insert this between the End If and End With portion of the function If (dteStart > dteRequest1) And ((dteEnd < dteRequest) And (dteRequest > dteStart)) Then MsgBox "Date Range Already Booked " & _ vbCrLf & dteStart & " Thru " & dteEnd DoCmd.CancelEvent Exit Function End If I haven't tested this throughly so you may have to work with it some, but I think you will understand how to go about it. lwells |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft Access Development > Availability |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|