Error in code of double bookings for hotel system

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pearwhat
    New Member
    • May 2014
    • 3

    Error in code of double bookings for hotel system

    I'm very new to vba code, so new that i find it hard to follow tutorials, i found this link in this website to prevent double bookings: http://bytes.com/topic/access/answer...ouble-bookings

    I created a form and created a button called "make booking" in this form, where i pasted this code that i got on the link in the "onclick" tab of the event menu in the property sheet:

    Code:
    Private Sub Book_Click()
    If Me.NewRecord = True Then
        Dim strWhere As String, strMessage As String
        Dim rsClone As Recordset
     
        strWhere = "((Room No=" & Me.Room No & _
                   ") AND (Reservation Out Date>=#" & _
                   Format(Me.Reservation In Date, "m/d/yyyy") & _
                   "#) AND (Reservation In Date<=#" & _
                   Format(Me.Reservation Out Date, "m/d/yyyy") & _
                   "#))"
     
        Set rsClone = Me.RecordsetClone
        rsClone.MoveFirst
        rsClone.FindFirst strWhere
     
        If rsClone.NoMatch Then
            MsgBox ("test")
            Cancel = True
            Exit Sub
        End If
    End If
    End Sub
    i get an expression error. I am not sure what I have done wrong, is it that I have put the code in the wrong area? if so where should I put it? I also need to know if the field "Reservatio n In Date" can be written as "Reservatio n In Date"or should i put it as "Reservation_In _Date" in the code, thanks for ur time:)
    Last edited by Rabbit; May 28 '14, 04:03 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • pearwhat
    New Member
    • May 2014
    • 3

    #2
    further info:
    the problem seemsto be with this bit of code:

    Code:
    strWhere = "((Room No=" & Me.Room No & _
    ") AND (Reservation Out Date>=#" & _
    Format(Me.Reservation In Date, "m/d/yyyy") & _
    "#) AND (Reservation In Date<=#" & _
    Format(Me.Reservation Out Date, "m/d/yyyy") & _
    "#))"
    As this appears in red and an error message popped saying "expression end not found"
    Last edited by Rabbit; May 28 '14, 04:04 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.

    Comment

    • pearwhat
      New Member
      • May 2014
      • 3

      #3
      further info:
      i did change the field names and add underscores, just t see if thatwas the error, so i changed it in the code aswell but, now it doesnt work at all, it just adds the record onto the table disregarding double bookings.

      Before changing the field name in the table, i just changed them in the code, and it didnt work properly, the messagebox didnt appear,it just updated the table with the new record and deleted the earlier record

      Comment

      • jimatqsi
        Moderator Top Contributor
        • Oct 2006
        • 1293

        #4
        pearwhat,
        Welcome to Bytes.com. There's lots of people here willing and able to help with programming problems. However, it's nearly impossible to provide coding help to someone who pasted something they found on the Internet and want to know why it doesn't work because they don't understand the code.

        Everyone starts off not understanding the code because they're very new to the language. There's no shame in that, for sure. But it's up to you to take the time and do the work that brings understanding. Since you have moved ahead without simply waiting for someone to solve your problem, I'd say you are trying to do exactly that.Make sure you study the samples you can find in the Northwind database. You can find that under the Help section of Access.

        I suspect your problems in this code are pretty simple. You've got the code in the right place, the click event of a control, probably it's a button. If the name of an object or field has spaces in it you MUST put [] around the name. So Reservation Out Date should be [Reservation Out Date]. You can avoid that by changing the spaces to underlines but then you have to do that everywhere. If it's a control on a form the name of the control must be changed along with the code; if it's a field in a table, the table definition must be changed as well as the code.

        I hope I've helped you get along a little further.

        Jim

        Comment

        • jimatqsi
          Moderator Top Contributor
          • Oct 2006
          • 1293

          #5
          Also, please put your code in Code tags when you make a post. Click the [CODE/} button and put your code between the tags. This is import to do.

          Jim

          Comment

          Working...