Results 1 to 6 of 6
  1. #1
    sjs94704 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Location
    Berkeley, CA
    Posts
    20

    Modifying a function

    I am creating a car rental database. This function is in the OnClick event of the command button to close a car rental contract. Its purpose is to change the status of the car selected from available to rented.



    My desired result is to change this routine so that if the user pulls up an existing contract and changes cars for some reason, that the routine is sure to mark the old car as 1 for available and the new car selected as 2 rented.

    How should I change the code?


    Public Function RentCar()

    Dim db As Database
    Dim rs As Recordset
    Set db = CurrentDb
    Set rs = db.OpenRecordset("SELECT * from CarProfileT WHERE CarProfileID=" & Forms!CarRentalContractF!CarProfileCombo)
    rs.Edit
    rs!StatusID = 2 ' Rented
    rs.Update
    rs.Close
    db.Close
    Set rs = Nothing
    Set db = Nothing


    End Function

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Have you considered using DateRented and DateReturned as an indicator of "available"?

  3. #3
    sjs94704 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Location
    Berkeley, CA
    Posts
    20
    Well, that won't work because I will use this same routine for if the car is out for repair, so DateRented and DateReturned are not the only choices.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It would still indicate "available" or not regardless of why it is out.

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Have you considered what data your function will need in order to achieve the results you desire? How is it going to get that information?

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    Have you created your tables and relationships?
    Here is a free, existing model that may give you some ideas
    http://www.databaseanswers.org/data_...hire/index.htm

    And here are the business facts that underlie the model
    http://www.databaseanswers.org/data_...ness_rules.htm

    Good luck with your project

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Modifying a database
    By simba in forum Access
    Replies: 0
    Last Post: 06-15-2011, 11:32 AM
  2. Modifying contacts search box
    By RemonKoybito in forum Programming
    Replies: 2
    Last Post: 06-03-2011, 09:23 AM
  3. modifying data from ODBC
    By Noewon in forum Queries
    Replies: 4
    Last Post: 03-03-2011, 08:23 PM
  4. Help needed in modifying Function
    By Alex Motilal in forum Programming
    Replies: 4
    Last Post: 02-06-2011, 11:59 PM
  5. Modifying Update Query
    By James Elvin in forum Queries
    Replies: 0
    Last Post: 10-14-2008, 09:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums