Results 1 to 11 of 11
  1. #1
    Thomman is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    8

    Create a history file

    Hi, Please help to solve this...
    I am Currently doing one Access project. One form contains many records to enter like AssetId,AssetDescription,DriverId,StartDate,EndDat e,,etc.. I need to create a history file for Drivers. Whenever a driver is changed his vehicle to another vehicle, it must be recorded into a history file with the driverId, StartDate and EndDate.

    Thomman

  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    I sure hope all of that isnt on a single table. You should have one table that contains the assets, one that has driver information, and a junction table (many to many relationship) that will list the information (dates of assignment, etc) that links the drivers to the assets. That junction table will essentially be your history table.

    Once the first two tables are set up behind the scenes, data entry will not have to enter in info regarding asset or driver. You can use comboboxes and let them select. once they are selected, the user enters the date, hits a button and you have your junction table updated. This both creates your history table, and minimizes data entry errors like typos or issuing a driver that doesnt exist to an asset.

  3. #3
    Thomman is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    8

    History file

    There are three tables.. 1. Assets 2. Drivers 3. DriversHistory. The DriverHistory file contains AssetID,DriverID,StartDate,EndDate...


    Thomman

  4. #4
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    That looks correct. What is the relationship between those tables? It should be:
    Assets 1----M DriversHistory M-----1 Drivers

    So now you will have 2 comboboxes on your form. the first one will hold asset information from the Asset table. the second will hold driver information from the Drivers table.

    Then you will have 2 text boxes. 1 for the user to enter the start date, and 1 for the user to enter the end date.

    Then you will create a button that will run a query:
    INSERT INTO DriverHistory (DriverID, AssetID, StartDate, EndDate)
    Values (Forms!myForm!cmbDriver, Forms!myForm!cmbAsset, Forms!myForm!txtStart, Forms!myForm!txtEnd)

    This will populate your DriverHistory table with the proper info. Now when you want to find records, you can query off of your DriverHistory table.

  5. #5
    Thomman is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    8

    Create a history file

    Really Thanks to you. Agian some more help in this..

    Instead of two text boxes, only one text box will be there. i.e StartDate.
    There exists one driver or for a new entry the field is empty.

    The policy is "the New driver's StartDate should be the EndDate of the the existing Driver..."

    Then instead of creating a button to run the query, we need to create a trigger like this....
    If the existing Driver (previous value in the DriverId) is changed with a new Driver, the form should display a message box and if we proceed then the query should be run.

    Thomman

  6. #6
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    so end date would be left blank until a new driver is assigned. you would run a second INSERT INTO but this time your you would have a WHERE clause as well. I dont have access to Access (i hate that phrase) right now and i wont again until tuesday so I cant confirm the SQL below is valid (it should be) but the logic would be:

    INSERT INTO DriversHistory (endDate)
    VALUES (Forms!myForm!txtStart)
    WHERE DriversHistory.Asset=Forms!myForm!cmbAsset AND DriversHistory.endDate is null

    The above will take your start date and enter it into the end date of the record that has both your asset number and a blank end date (there should only be one record with a blank end date if your records are correct).

  7. #7
    Thomman is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    8

    Create a history file

    When I used this I get Sytanx Error!!!

  8. #8
    Datagopherdan is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Dec 2008
    Posts
    220
    Parameters in queries are limited. You're getting the error because of the combo box reference. Also, it looks like you would want to do an update statement not an append. Try doing it in VBA like below. I'm assuming that your combo box is grabbing a numeric value, if not you would need to change "intAsset" to a string variable.

    Code:
    Dim dtStart As Date
    Dim intAsset As Integer
    If IsNull(Me.txtStart) Then
        MsgBox "You must enter a date"
            Exit Sub
    End If
    dtStart = Me.txtStart
    intAsset = Me.cmbAssest
    CurrentDb.Execute "UPDATE DriversHistory SET DriversHistory.endDate = " & dtStart & _
    " WHERE Asset= " & intAsset & " AND endDate is null"
    Dan
    Access Development

  9. #9
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    Eh, like I said about my syntax, I dont have Access available to try it out when I'm at home. Hope it works out.

  10. #10
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    It is always essential to enclose Date with "#" when using SQl to Insert or update Table. Otherwise you may get undesirable results.

    My suggestion will be

    CurrentDb.Execute "UPDATE DriversHistory SET DriversHistory.endDate = #" & dtStart & _
    "# WHERE Asset= " & intAsset & " AND endDate is null"

  11. #11
    Datagopherdan is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Dec 2008
    Posts
    220
    Thanks for adding that in, Maximus. You're absolutely right. You do always want to make sure you have the correct syntax for the type of variable such as "#" in this case.

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

Similar Threads

  1. Access records with history
    By crosbytr in forum Database Design
    Replies: 0
    Last Post: 03-21-2010, 06:08 PM
  2. Create Hash - Copy File to string
    By andrew_ww in forum Programming
    Replies: 0
    Last Post: 03-20-2010, 02:14 AM
  3. Comment History
    By botts121 in forum Programming
    Replies: 0
    Last Post: 07-02-2009, 01:02 PM
  4. Client History
    By janjan_376 in forum Access
    Replies: 1
    Last Post: 06-23-2009, 02:44 AM
  5. Create a command button to Browes for file
    By sawill in forum Programming
    Replies: 3
    Last Post: 03-15-2009, 05:02 PM

Tags for this Thread

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