Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004
    Location
    Scotland
    Posts
    24

    Unanswered: SQL and VBA code problem

    Hi there

    Can anyone check this code and tell me where i've gone wrong....please!

    VBA code is:

    Code:
    Private Sub ConfirmBooking_Click()
        Dim DB As DAO.Database
        Dim rst As DAO.Recordset
        
        Set DB = CurrentDb()
        Set rst = DB.OpenRecordset("qryBooking")
        
        If rst.BOF And rst.EOF Then
            Call MsgBox("Your booking is confirmed", vbExclamation, "Booking Confirmed")
            DoCmd.GoToRecord , , acNewRec
        Else
            rst.MoveFirst
            Do Until rst.EOF
                If rst.RecordCount > 0 Then
                    Call MsgBox("Sorry this aircraft is already booked, please choose another time", vbCritical, "Error")
                End If
            rst.MoveNext
            Loop
        End If
      End Sub
    and the SQL query code is:
    Code:
    SELECT BookingDetails.AcReg, BookingDetails.HireDate, BookingDetails.StartTime, BookingDetails.EndTime, BookingDetails.TimeSheetId
    FROM BookingDetails
    WHERE (((BookingDetails.AcReg)=Forms!BookingForm!cboAcReg) 
    And 
    ((BookingDetails.HireDate)=Forms!BookingForm!cboHireDate) 
    And 
    ((BookingDetails.StartTime) Between forms!bookingform!cboStarttime And Forms!BookingForm!cboEndTime) 
    And 
    (Not (BookingDetails.TimeSheetId)=forms!bookingform!timesheetid)) 
    Or (((BookingDetails.AcReg)=Forms!BookingForm!cboAcReg) 
    And ((BookingDetails.HireDate)=Forms!BookingForm!cboHireDate) 
    And ((BookingDetails.EndTime) Between forms!bookingform!cboStarttime And Forms!BookingForm!cboEndTime) 
    And (Not (BookingDetails.TimeSheetId)=forms!bookingform!timesheetid));
    All this is meant to check for duplicates and if it finds any return the error msgbox or the confirmation msgbox if none are found.

    where have i gone wrong??

    TIA
    Cam

  2. #2
    Join Date
    Mar 2004
    Posts
    118
    What is it doing wrong?

    You seem to be pulling all the data out of forms. From my experience access froms have a tendency to store 'ghosts' values in fields that appear null. Might be an idea to base your query from the original tables.

  3. #3
    Join Date
    Apr 2004
    Location
    Scotland
    Posts
    24

    Soory forgot to tell the error type

    Hi

    the error i get from my original post is:

    Run time error 3061
    too few parameters: expected 4

    I don't understand this error message and as usual the help file isn't!

    Any pointers!

    ps i have removed the
    Code:
     And (Not (BookingDetails.TimeSheetId)=forms!bookingform!timesheetid));
    from the query! - not that i think it'll matter any as timesheet was a field linking to another form!

    Thanks again
    Cam

  4. #4
    Join Date
    Apr 2004
    Location
    Scotland
    Posts
    24
    never mind - got it to work doing something else!

Posting Permissions

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