Results 1 to 7 of 7
  1. #1
    jlt199 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2014
    Posts
    34

    Maintaining Data Integrity

    I'm going around and around in circles of ever increasing frustration

    I have a form, on my form I have a combobox which contains the IDs of all the patients in my database. The form is for editing existing records and adding new records every time a patient fills in a form. It is possible for the patient to exist in the database, but have no form entries. It is also possible that the patient may not be in the database at all.

    I would like to use the combobox purely for searching records, not for overwriting existing data. The process I am going for is



    1. If the patient does not exist in the database ask user (via a dialog box) if they would like to add them. If yes, open the form for adding new patients. Set ID value in main form back to a value that exists.
    2. If a patient exists but does yet have any records associated to them inform the user (via dialog box) and ask them if them would like to add a first record for this patient. If yes, go to new record and auto-fill ID box with the user entered ID. Otherwise, revert back to ID (and record) shown before user updated value.
    3. If patient exists and has records, use a filter to find them all.


    My current problem is with item 2. I can go to a new record and auto-fill the ID number. I enable all the other controls on the form so that the user can set their values for this record. However, I can't seem to be able to save this new record correctly though. When the user updates the value in the ID box again, to search and filter for the next patient, the new record is saved with this ID and not the ID intended.

    The ID combo box should never allow existing data to be overwritten.

    Can anyone help me with this please?

  2. #2
    jlt199 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2014
    Posts
    34
    Also the record I was looking previously to entering a patient ID that didn't yet have a record associated to it, and triggering event 2 above, gets overwritten with the new ID. This should not happen

  3. #3
    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,848
    What is the rowsource of the combo?
    What is the form for?
    You should be able to query the database and determine if a patient exists or not.
    If not, then new.
    If already exists, then what? Why would a patient be in db but not on form? It's your program, please tell us about the database and the form.

  4. #4
    jlt199 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2014
    Posts
    34
    My rowsource for the combobox comes from a Table called "Patients" that contains all of the patient info, name, gender etc.

    I have found a way to query the database to determine a) does the patient exist in the "Patient" table and b) does that patient have any existing records in the "PatientRecords" table.

    If a) is false then I trigger the user to open the "AddPatient" form. If b) is false then I goto a new record in the current form (attached to the "PatientRecords" table) and insert the ID they gave in the ID box. If both queries are true then I search for the relevant records.

    My problem is that in the process of going to a new record in the case of b) being false, I overwrite the ID of the previous record I was looking with this new ID. I also can't seem to save this new record with the intended ID. It always gets overwritten when I try and search for the next patient.

    Can I prevent a combobox from overwriting data in existing records? Can I force the form to save a record when I want it to and not when it thinks I should?

  5. #5
    jlt199 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2014
    Posts
    34
    After several hours I think I may have the answer. Before doing anything in the "AfterUpdate" event I now save the entered ID into a LocalVar and UNDO the record before going down any of the update routes. This seems to work, but also seems clunky. Am I missing something? Thanks

  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,848
    Try the before update event . Do the checking etc and you can cancel if needed.

    I don't understand why there is an issue with overwriting the ID. Can you describe the set up? And show us (jpg) your table designs and relationships?

  7. #7
    jlt199 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2014
    Posts
    34
    These are my table relationships
    Click image for larger version. 

Name:	tableRelationships.jpg 
Views:	7 
Size:	94.4 KB 
ID:	15582

    This is my form design

    Click image for larger version. 

Name:	PatientRecordsForm.jpg 
Views:	7 
Size:	35.5 KB 
ID:	15583

    If I enter an ID that is in the Patients table, but not in the PatientsRecords table then I get a dialog box that takes me to a new record


    Click image for larger version. 

Name:	newRecord.jpg 
Views:	7 
Size:	34.1 KB 
ID:	15585

    My beforeUpdate macro for the PHN combobox
    Click image for larger version. 

Name:	beforeUpdateMacro.jpg 
Views:	6 
Size:	37.6 KB 
ID:	15586

    My afterUpdate macro for the PHN combobox

    Click image for larger version. 

Name:	afterUpdateMacro.jpg 
Views:	7 
Size:	23.1 KB 
ID:	15587

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

Similar Threads

  1. Replies: 1
    Last Post: 10-03-2013, 01:35 PM
  2. Replies: 8
    Last Post: 12-01-2012, 04:17 PM
  3. Replies: 1
    Last Post: 05-20-2012, 01:22 AM
  4. maintaining inventory in access
    By mmarwaha in forum Access
    Replies: 1
    Last Post: 01-16-2011, 06:23 AM
  5. Data preventing Referential Integrity
    By RubberStamp in forum Access
    Replies: 0
    Last Post: 12-14-2008, 05:43 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