Results 1 to 10 of 10

Thread: [Resolved] Access VBA - Checking for entry on the fly

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    48

    [Resolved] Access VBA - Checking for entry on the fly

    Im writing a booking system for a school room in Access, as the school wants it done in an office package!

    I need to check wether a booking for the date, time and area has already been made one the three relevant fields have been filled. (areaID [number] , bookingDate [short date], timeID [number]) what ever i do seems to not work.

    Ive tried a "SELECT INTO" then "SELECT COUNT" SQL statement but had no joy with that!

    Any ideas?
    Last edited by c03cg; Jul 18th, 2006 at 09:26 AM.

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Access VBA - Checking for entry on the fly

    VB Code:
    1. If IsNull(Dlookup("AreaID","TABLE NAME","bookingDate=#" & dDate & ")) Then
    2. 'Date Not used
    3. Else
    4. 'Date taken
    5. End If
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    48

    Re: Access VBA - Checking for entry on the fly

    Coolies... ill write some code then post it for marking (",)

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    48

    Re: Access VBA - Checking for entry on the fly

    ok.... so it doesn't seem to work quite right.... if i edit a record its fine, but if im adding a record it lets me do any date/time/area combo.

    VB Code:
    1. Private Sub calBookingDate_Click()
    2.    
    3.     '--- Set [bookingDate] to date selected on calendar ---'
    4.     bookingDate.Value = calBookingDate.Value
    5.    
    6.     checkBooking bookingDate.Value, timeID.Value, areaID.Value
    7.    
    8. End Sub

    VB Code:
    1. Function checkBooking(dDate As Date, iTime As Integer, iArea As Integer)
    2.            
    3.     '--- Check to see if date/area combo is not taken ---'
    4.     If IsNull(DLookup("areaID", "booking", "bookingDate=#" & dDate & "#")) Then
    5.     '--- Area is not being used on the selected date ---'
    6.    
    7.         MsgBox "Date Not used"
    8.        
    9.     Else
    10.     '--- Area is being used on the selected date ---'
    11.    
    12.         MsgBox "Date taken"
    13.        
    14.         '--- check to see if area/date/time combo is free ---'
    15.         If IsNull(DLookup("areaID", "booking", "timeID=" & iTime & "")) Then
    16.         '--- Area/date/tim is free ---'
    17.        
    18.             MsgBox "Time Slot Not Taken"
    19.                
    20.         Else
    21.         '--- Area/date/tim is taken ---'
    22.        
    23.             MsgBox "Time Slot Taken"
    24.                
    25.         End If
    26.    
    27.     End If
    28.    
    29. End Function

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    48

    Re: Access VBA - Checking for entry on the fly

    Right..... any one up for sorting this one out?:

    VB Code:
    1. If Not IsNull(DLookup("areaID", "booking", "areaID=" & areaID)) Then
    2.     '--- Area is not being used ---'
    3.        
    4.         sError = "A"
    5.                
    6.     End If
    7.    
    8.     If Not IsNull(DLookup("bookingDate", "booking", "bookingDate=#" & dDate & "#")) Then
    9.     '--- Area and date are not being used ---'
    10.            
    11.         sError = sError & "D"
    12.        
    13.     End If
    14.    
    15.     If Not IsNull(DLookup("timeID", "booking", "timeID=" & timeID)) Then
    16.     '--- Area, date and time are not being used ---'
    17.        
    18.         sError = sError & "T"
    19.        
    20.     End If
    21.    
    22.     MsgBox sError

    This is split apart so i could test it......but

    The First and third work fine but the date bit only works on the first record in the table (currently 07/06/2006) but wont recognise the second (08/06/2006) why?!?!?!?!

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Access VBA - Checking for entry on the fly

    access database reqire date to be "mm/dd/yyyy", if you are trying to use "dd/mm/yyyy" you will get problems, you need to format your date to suit.

    i can't really tell if this is you problem, just seems as if it might.

    pete

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    48

    Re: Access VBA - Checking for entry on the fly

    Yes.... that was the problem..... I'd just trawled thru googles results and found that out so ive done this:

    VB Code:
    1. Dim dDate As Date
    2.     Dim sDate() As String
    3.     Dim iTime As Integer
    4.     Dim sError As String
    5.  
    6.     '--- Set [bookingDate] to date selected on calendar ---'
    7.     bookingDate.Value = calBookingDate.Value
    8.  
    9.     dDate = bookingDate.Value
    10.     iTime = timeID.Value
    11.    
    12.     sDate = Split(dDate, "/")
    13.     dDate = sDate(1) & "/" & sDate(0) & "/" & sDate(2)

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Access VBA - Checking for entry on the fly

    VB Code:
    1. mydate = format(sdate, "mm/dd/yyyy")

    should work i think

    pete

  9. #9

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    48

    Re: Access VBA - Checking for entry on the fly

    cool, that works even better

  10. #10

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    48

    Re: Access VBA - Checking for entry on the fly

    Right the code all works and the result is:

    VB Code:
    1. If Not IsNull(DLookup("timeID", "booking", "timeID=" & iTime)) _
    2.             And Not IsNull(DLookup("bookingDate", "booking", "bookingDate=#" & dDate & "#")) _
    3.             And Not IsNull(DLookup("areaID", "booking", "areaID=" & iArea)) Then
    4.        
    5.             sCode = DLookup("staffCode", "booking", "bookingDate = #" & dDate & "# AND timeID = " & iTime & " AND areaID = " & iArea)
    6.                
    7.             sForename = DLookup("[staffForeName]", "staff", "[staffCode] = '" & sCode & "'")
    8.        
    9.             sSurname = DLookup("staffSurName", "staff", "staffCode = '" & sCode & "'")
    10.                
    11.             MsgBox "The booking has already been booked by " & sForename & " " & sSurname
    12.        
    13.         End If

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