Results 1 to 4 of 4
  1. #1
    Nikko is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    3

    VBA help for allowing only 1 selected appointment time.

    Evening everyone,

    New to the forums and also new to the vba world. I'm hoping someone may be able to direct me on how I am able to achieve this.

    Currently I'm trying to create a quick appointment schedule.

    We allow for 15 minute appointments between the hours of 2:00 PM and 4:00 PM.

    I would like it if someone chose the appointment time 2:15 PM within the combo box, it would not show up again for that day unless that appointment was deleted.
    I've had some help with the code below, but I am unable to get it to only recognize 1 time slot per day. This code allows me to select 2:15 multiple times.




    Code:
    Sub cboTime_enter()   
       Dim dteTime As Date
        
       Me.cboTime.RowSource = ""
       dteTime = #2:00:00 PM#
       Do While dteTime <= #4:00:00 PM#
          If dteTime <= Time() Then
             Me.cboTime.AddItem Format(dteTime, "h:nn AMPM")
          End If
          dteTime = DateAdd("n", 15, dteTime)
       Loop
       
    End Sub
    Any assistance is appreciated.
    Thanks.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    the query in the combo box must be an outer join. qsFreeTime.
    To find the time in available Time but not in qsAppts (used time)

    qsAppts, is a query on the already existing appts for that day. 215 is in it.
    now make another query, qsFreeTime,
    in it bring in qsAppts and the table with all times,tTimeBlock.
    join the 2 on TIME, dbl-click the join line,
    set the property to ALL items in tTimeBlock, SOME items in qsAppts. (outer join)
    bring down TIME field from both , tTimeBlock.Time , qsAppts.Time (this one doesnt have to be visible)
    set qsAppts.Time IS NULL

    no only available blocks will show in combo.

  3. #3
    Nikko is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    3
    This makes sense. Unfortunately I do not have time this morning to work on it.
    I appreciate the feedback and I'll get to work on this today at some point.

    Thanks ranman.

  4. #4
    Nikko is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    3
    Quote Originally Posted by ranman256 View Post
    the query in the combo box must be an outer join. qsFreeTime.
    To find the time in available Time but not in qsAppts (used time)

    qsAppts, is a query on the already existing appts for that day. 215 is in it.
    now make another query, qsFreeTime,
    in it bring in qsAppts and the table with all times,tTimeBlock.
    join the 2 on TIME, dbl-click the join line,
    set the property to ALL items in tTimeBlock, SOME items in qsAppts. (outer join)
    bring down TIME field from both , tTimeBlock.Time , qsAppts.Time (this one doesnt have to be visible)
    set qsAppts.Time IS NULL

    no only available blocks will show in combo.
    This is great. The only issue I seem to have now is that I'm unable to see the used times (of today) as available (tomorrow) when I change the date of the appointment.

    ex: 2:00 PM is used today.
    If I were to change the calendar picker to tomorrows date, 2:00 PM should be visible.

    I have attempted to try a similar query as you said but for appointment times. I was unsuccessful.

    I have attached my current db if that is any help.

    Thanks ranman. You've already helped a great deal.

    schedule.mdb

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Cancel appointment
    By ictcrystal in forum Forms
    Replies: 1
    Last Post: 03-08-2015, 05:51 PM
  2. Replies: 1
    Last Post: 05-31-2013, 02:04 AM
  3. Appointment Due
    By cheechootrain in forum Access
    Replies: 8
    Last Post: 05-20-2013, 06:25 PM
  4. Appointment Generator
    By cheechootrain in forum Access
    Replies: 15
    Last Post: 04-23-2013, 12:37 PM
  5. Replies: 3
    Last Post: 04-09-2013, 01:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums