Results 1 to 3 of 3

Thread: Syntax error on vb code no one has been able to solve this yet. i am new to this and

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    1

    Question Syntax error on vb code no one has been able to solve this yet. i am new to this and

    Ihave tryed many different ways to get this to work biyt am still getting sytax errors.
    Can any find the problem or come up wiyj an alternitive?

    Private Sub addrecord_Click()
    On Error GoTo Err_addrecord_Click

    If Dcount ("[Reservation Date] = " & ReservationDate & " AND "[Asset ID] = " & AssetID & " AND " & TimeBookedIn & " BETWEEN [Time Booked Out] AND [Time Booked In] OR " & TimeBookedOut & " BETWEEN [Time Booked Out] AND [Time Booked In])") > 0 Then
    'MsgBox "Dulpicte Record, change asset ID or booking time"
    Else
    DoCmd.GoToRecord , , acNewRec


    End If




    Exit_addrecord_Click:
    Exit Sub

    Err_addrecord_Click:
    MsgBox Err.Description
    Resume Exit_addrecord_Click

    End Sub



    I want to prevent any double booking can any on help

    I am a beginner in access so go easy on me ļ

    For example:

    Customer 1 wants an asset from:
    Date: 11/11/04
    Time Booked Out14:00
    Time Booked In16:00

    Customer 2 wants to book the same asset from:
    Date: 11/11/04
    Time Booked Out 15:00
    Time Booked In 17:00

    The tables I have:

    Reservations
    Reservation ID
    Reservation Date
    Asset ID
    Booked Out
    Booked In
    Customer ID


    Asset
    Asset ID
    Asset Description
    Asset Photo

    Service Records
    Service Record ID
    Asset ID
    Description
    Problem Date
    Resolved Date

    Customers
    Customer ID
    Customer First Name
    Customer Last Name

    Assets
    Asset ID
    Time Collected
    Time Returned

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    Try something like this.....HTH

    VB Code:
    1. 'First select all records in your database then when you click Save use this code to check for a duplicate.
    2.  
    3. Do Until YourRecordset.EOF = True
    4.  
    5. If YourRecordset![Reservation Date] = " & ReservationDate & " _ AND YourRecordset![Asset ID] = " & AssetID & "
    6. AND " & _ TimeBookedIn & " BETWEEN YourRecordset![Time Booked Out] AND YourRecordset![Time Booked In] OR
    7.  " & TimeBookedOut & " _ BETWEEN YourRecordset![Time Booked Out] AND Time Booked In > 0 Then
    8. MsgBox "Dulpicte Record, change asset ID or booking time"
    9. Exit Sub
    10. End If
    11.  
    12. YourRecordset.Movenext
    13.  
    14. Loop
    15.  
    16. DoCmd.GoToRecord , , acNewRec
    17.  
    18.  
    19. End If

  3. #3
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    Hi

    Probably Lintz's code will work (post up if it does!)


    VB Code:
    1. strSql="Select tblReservations.* From tblReservations "
    2. strSql=strSql & "Where [RDate]=#" & dteDate & "# and [AssetID]=" & lngAssetID & " and ( "
    3. strSql=strsql & "#" & dteTimeOut & "# between [bookedout] and [bookedin] or #" & dteTimeIn & "# between [bookedout] and [bookedin])"
    4.  
    5.  
    6. 'open a recordset with the above sql
    7. if rst.eof then
    8. '---- create a record its ok
    9. else
    10. '---- there is at least one record within that time for that Asset and date
    11. '---- so do a notice to the user...
    12. end if
    dte - variables of Date
    rst - variable of recordset (either DAO or ADO)
    strSql - variable of string (holds sql statement)

    The Sql should bring back all records for the asset specified, on the date specified, and most importantly bring back any records which the times are in between. If no records are returned then you can go ahead and save...

    Worth the time to experiment and post up which method works best?


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width