By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,397 Members | 1,374 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,397 IT Pros & Developers. It's quick & easy.

Error in code of double bookings for hotel system

P: 3
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:

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:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Book_Click()
  2. If Me.NewRecord = True Then
  3.     Dim strWhere As String, strMessage As String
  4.     Dim rsClone As Recordset
  6.     strWhere = "((Room No=" & Me.Room No & _
  7.                ") AND (Reservation Out Date>=#" & _
  8.                Format(Me.Reservation In Date, "m/d/yyyy") & _
  9.                "#) AND (Reservation In Date<=#" & _
  10.                Format(Me.Reservation Out Date, "m/d/yyyy") & _
  11.                "#))"
  13.     Set rsClone = Me.RecordsetClone
  14.     rsClone.MoveFirst
  15.     rsClone.FindFirst strWhere
  17.     If rsClone.NoMatch Then
  18.         MsgBox ("test")
  19.         Cancel = True
  20.         Exit Sub
  21.     End If
  22. End If
  23. 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 "Reservation In Date" can be written as "Reservation In Date"or should i put it as "Reservation_In_Date" in the code, thanks for ur time:)
May 28 '14 #1
Share this Question
Share on Google+
4 Replies

P: 3
further info:
the problem seemsto be with this bit of code:

Expand|Select|Wrap|Line Numbers
  1. strWhere = "((Room No=" & Me.Room No & _
  2. ") AND (Reservation Out Date>=#" & _
  3. Format(Me.Reservation In Date, "m/d/yyyy") & _
  4. "#) AND (Reservation In Date<=#" & _
  5. Format(Me.Reservation Out Date, "m/d/yyyy") & _
  6. "#))"
As this appears in red and an error message popped saying "expression end not found"
May 28 '14 #2

P: 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
May 28 '14 #3

Expert 100+
P: 1,240
Welcome to 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.

May 28 '14 #4

Expert 100+
P: 1,240
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.

May 28 '14 #5

Post your reply

Sign in to post your reply or Sign up for a free account.