AcessHelp89
Registered User.
- Local time
- Today, 21:21
- Joined
- Jan 3, 2014
- Messages
- 12
Hey Guys
I created a form for scheduling appointments on access 2013 using a youtube tutorial. I got most of it work apart from the combo box that functions in a way that once the time slot has booked with a client it should no longer be shown in the list.
Eg:-2/2/2014 10:00AM is already booked with a client
the combo box should no longer display the 10:00 AM timeslot but can be shown on other days
Below is the VBA code that i typed out.
Could anyone help me create the code to make the combo box work in that manner.
It is part of a project i am doing and is due in very soon. can any of you guys help me out it would be much apreciated guys
Option Compare Database
Private Sub cboTime_Enter()
Dim i As Date, n As Integer, oRS As DAO.Recordset, sSQL As String
Dim dLowerbreak As Date, dUpperBreak As Date, dDuration As Date
Dim dLowerPrecision As Date, dUpperPrecision As Date
cboTime.RowSourceType = "Value List"
cboTime.RowSource = ""
If IsNull(Start) Then Exit Sub Else i = Start
If Me.NewRecord = True Then
DoCmd.RunCommand acCmdSaveRecord
End If
sSQL = "SELECT DoctorsID, AppointDate, AppointTime"
sSQL = sSQL & " FROM qrySubformAppoints"
sSQL = sSQL & " WHERE DoctorsID= " & Me.ID & _
" AND AppointDate=#" & Me.txtAppointDate & "#"
Set oRS = CurrentDb.OpenRecordset(sSQL)
dDuration = TimeValue("00:30")
dLowerbreak = Break - TimeValue("00:25") 'Break is a field
dUpperBreak = Break + TimeValue("00:25")
If oRS.RecordCount = 0 Then
Do
If i <= dLowerbreak Or i >= dUpperBreak Then
cboTime.AddItem i
End If
i = i + dDuration
Loop Until i >= txtEnd
Else
Do
If i <= dLowerbreak Or i >= dUpperBreak Then
dLowerPrecision = i - TimeValue("00:00:05")
dUpperPrecision = i + TimeValue("00:00:05")
oRS.FindFirst "[AppointTime] Between #" & dLowerPrecision & "# And #" & dUpperPrecision & "#"
If oRS.NoMatch Then cboTime.AddItem i
End If
i = i + dDuration
Loop Until i >= txtEnd
End If
oRS.Close
End Sub
Private Sub cboTime_AfterUpdate()
subform.SetFocus
DoCmd.GoToControl "AppointTime"
DoCmd.GoToRecord , , acNewRec
subform.Form.Controls("AppointTime") = Me.cboTime
subform.Form.Controls("AppointDate") = Me.txtAppointDate
subform.Form.Controls("cboClient").SetFocus
subform.Form.Controls("cboClient").Dropdown
End Sub
Private Sub txtAppointDate_BeforeUpdate(Cancel As Integer)
If CDate(txtAppointDate) <= Date Then
MsgBox "No more new appointments on this date"
Cancel = True
End If
End Sub
I found out that the combo box does not work like it does in the video i.e the option does not dissaspear even though their has been a booking with that time slot with another client.
Can anyone help me figure out the coding that is required to make the combo box work like that or is their an error within the code that is preventing the combo box to work in such manner
Thank You
I created a form for scheduling appointments on access 2013 using a youtube tutorial. I got most of it work apart from the combo box that functions in a way that once the time slot has booked with a client it should no longer be shown in the list.
Eg:-2/2/2014 10:00AM is already booked with a client
the combo box should no longer display the 10:00 AM timeslot but can be shown on other days
Below is the VBA code that i typed out.
Could anyone help me create the code to make the combo box work in that manner.
It is part of a project i am doing and is due in very soon. can any of you guys help me out it would be much apreciated guys
Option Compare Database
Private Sub cboTime_Enter()
Dim i As Date, n As Integer, oRS As DAO.Recordset, sSQL As String
Dim dLowerbreak As Date, dUpperBreak As Date, dDuration As Date
Dim dLowerPrecision As Date, dUpperPrecision As Date
cboTime.RowSourceType = "Value List"
cboTime.RowSource = ""
If IsNull(Start) Then Exit Sub Else i = Start
If Me.NewRecord = True Then
DoCmd.RunCommand acCmdSaveRecord
End If
sSQL = "SELECT DoctorsID, AppointDate, AppointTime"
sSQL = sSQL & " FROM qrySubformAppoints"
sSQL = sSQL & " WHERE DoctorsID= " & Me.ID & _
" AND AppointDate=#" & Me.txtAppointDate & "#"
Set oRS = CurrentDb.OpenRecordset(sSQL)
dDuration = TimeValue("00:30")
dLowerbreak = Break - TimeValue("00:25") 'Break is a field
dUpperBreak = Break + TimeValue("00:25")
If oRS.RecordCount = 0 Then
Do
If i <= dLowerbreak Or i >= dUpperBreak Then
cboTime.AddItem i
End If
i = i + dDuration
Loop Until i >= txtEnd
Else
Do
If i <= dLowerbreak Or i >= dUpperBreak Then
dLowerPrecision = i - TimeValue("00:00:05")
dUpperPrecision = i + TimeValue("00:00:05")
oRS.FindFirst "[AppointTime] Between #" & dLowerPrecision & "# And #" & dUpperPrecision & "#"
If oRS.NoMatch Then cboTime.AddItem i
End If
i = i + dDuration
Loop Until i >= txtEnd
End If
oRS.Close
End Sub
Private Sub cboTime_AfterUpdate()
subform.SetFocus
DoCmd.GoToControl "AppointTime"
DoCmd.GoToRecord , , acNewRec
subform.Form.Controls("AppointTime") = Me.cboTime
subform.Form.Controls("AppointDate") = Me.txtAppointDate
subform.Form.Controls("cboClient").SetFocus
subform.Form.Controls("cboClient").Dropdown
End Sub
Private Sub txtAppointDate_BeforeUpdate(Cancel As Integer)
If CDate(txtAppointDate) <= Date Then
MsgBox "No more new appointments on this date"
Cancel = True
End If
End Sub
I found out that the combo box does not work like it does in the video i.e the option does not dissaspear even though their has been a booking with that time slot with another client.
Can anyone help me figure out the coding that is required to make the combo box work like that or is their an error within the code that is preventing the combo box to work in such manner
Thank You