Results 1 to 8 of 8
  1. #1
    JackieFeng is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2016
    Posts
    24

    double booking code help!


    I am trying to find a way to prevent double booking.

    In my booking form, i have date(date/time),start time(date/time) and doctor ID(number)-all from tblBooking


    For example, doctor 1 9/6/2016 9:00. then next time i enter this information into form which should prevent me doing this and an error message should display.

    What code should i put into this form? (code for multiple fields)

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    something like

    if dcount("*","tblBooking","DoctorID=" & me.txtDoctorID & " AND StartTime = " & cdate(me.txtStartTime) & " AND StartDate=" & cdate(me.txtStartDate) <>0 Then msgBox "Time Already Booked"

    You say you have a field called Date - this is a reserved word and should not be used for a field name

  3. #3
    JackieFeng is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2016
    Posts
    24
    Thank you for replay.

    Private Sub Form_Load()
    DoCmd.GoToRecord , , acNewRec
    End Sub


    If dcount("'", "tblBooking","DoctorID=" & me.txtDoctorID &"
    AND StartTime = " & cdate(me.txtStartTime)&"
    AND ApptDate = "& cdate(me.txtAppDate)<>0


    Then msgBox "Time Already Booked"


    The code i entered are red color.. Do you know what the problem is ?

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    it needs to be in an event sub - you haven't explained how your form works so I didn't want to waste time guessing which event - but it will be the first one after all three fields have been completed by the user. Also, you a) have not copied my code properly and b) I would be very surprised if I guessed the names of your form controls correctly

  5. #5
    JackieFeng is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2016
    Posts
    24
    Click image for larger version. 

Name:	N[IW]J`9Y6Q10C)~MJE]28W.png 
Views:	17 
Size:	10.9 KB 
ID:	24557This is the error message... The fields are after update [Event Procedure]
    Attached Thumbnails Attached Thumbnails $]NTJAOFRT8ZUFO1[I413Q9.png  

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    If dcount("'", "tblBooking","DoctorID=" & me.txtDoctorID &"
    AND StartTime = " & cdate(me.txtStartTime)&"
    AND ApptDate = "& cdate(me.txtAppDate)<>0)'<------You need a closing bracket


    There is a sample database re reservations here
    You may find some info that is helpful

    Good luck.

  7. #7
    JackieFeng is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2016
    Posts
    24
    Click image for larger version. 

Name:	1.png 
Views:	17 
Size:	6.7 KB 
ID:	24559..This is my first time using code.. I closed bracket and it worked.. but another error message shown 'Only comments only appear after End Sub, End function.........

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    bracket is in the wrong place

    ......& cdate(me.txtAppDate))<>0

    Also you need some lessons on how to structure code

    This link may help - it is for excel vba but the principle is the same

    https://www.youtube.com/watch?v=aQKXzOJ4jSE

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

Similar Threads

  1. Unmatched Query to Prevent Double Booking
    By MAC987 in forum Access
    Replies: 1
    Last Post: 03-18-2016, 05:34 PM
  2. Replies: 5
    Last Post: 04-11-2015, 03:54 AM
  3. Replies: 7
    Last Post: 11-27-2013, 03:14 PM
  4. Replies: 2
    Last Post: 06-07-2013, 08:23 AM
  5. prevent double booking!! help!
    By Jean-Daniel in forum Access
    Replies: 5
    Last Post: 05-16-2012, 06:09 AM

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