+ Reply to Thread
Results 1 to 14 of 14

Matching patient personal data to that already stored in a database

  1. #1
    Registered User
    Join Date
    06-16-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Red face Matching patient personal data to that already stored in a database

    I am trying to write a macro to transfer patient personal data onto a database.

    On sheet 1 the user inputs the patient surname, forename, date of birth, date of test and the test results.

    On sheet 2 is the database, where patient surname, forename and date of birth is stored in columns A, B and C respectively. The remainder of the columns on each row is available for scoring test results.

    What I would like the macro to do is as follows:
    • Read the patient surname as input on sheet 1
    • Check on sheet 2 if that surname already exists
    • If it does, check if the forename and date of birth also match to sheet 1 for that particular entry.
    • If a match is found then copy the test results into a column on that particular row. E.g. could be copied into column D.
    • If no match is found, then all the data is entered as a new row on the database (I’ve written the code for this bit but thought I should add it in for clarity)

    This will then allow all test results for a particular patient to be read off the same row in the database.

    I've been playing around with it for a few days but still cant get it to work. Any help offered much appreciated!

    Helen

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Matching patient personal data to that already stored in a database

    See the Contacts form example here

    http://www.excel-it.com/vba_examples.htm
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    06-16-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Matching patient personal data to that already stored in a database

    Thanks RoyUK, am downloading the example now - will let you know how i get on!

    Helen

  4. #4
    Registered User
    Join Date
    06-16-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Matching patient personal data to that already stored in a database

    Ok, this is the code i have so far for checking whether the data from sheet 1 (data entry) matches an existing entry on sheet 2 (database). Not sure if this is the best way of doing it but it works!

    Please Login or Register  to view this content.
    The problem i'm having now is with the 'perform copy function as follows.

    If the code finds the outcome of the above IF to be true, i then want to copy some data into column F of sheet 2 (database) on the SAME ROW where the code has found the match. I've tried using ActiveCell.row but can't get it to work - maybe this isnt the best approach??

    Cann anyone help me with this?

    Helen

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Matching patient personal data to that already stored in a database

    You don't need to select the sheet.
    I can't tell what your variables are such as surname, is it a range?
    Looping is an ineficient method to use.

    Attach an example workbook with dummy data in it

  6. #6
    Registered User
    Join Date
    06-16-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Matching patient personal data to that already stored in a database

    Hi,

    I have attached an example workbook with dummy data and modified my code for this dummy data.

    The user would input the data on the "data entry" sheet and the results displayed in the "database" sheet. In my original document i achieve this using a button to activate the macro.

    Hopefully this will explain better what i'm trying to achieve. After having identified a match between the information on the "data entry" sheet and an existing entry on the "database" sheet, i then want to copy and paste the test results onto the corresponding row on the "database".

    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Matching patient personal data to that already stored in a database

    Your code should be in a procedure, i.e surrounded by
    Please Login or Register  to view this content.
    You haven't declared the variables - this is bad practice.

    Use .Find to check for entries.

    Did you look at the example, it should be simple to adapt it?
    Last edited by royUK; 06-18-2009 at 07:52 AM.

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Matching patient personal data to that already stored in a database

    I would think that adding a field for national Insurance or NHS patient ID would be a good idea & simplify the checks.

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Matching patient personal data to that already stored in a database

    See if this does what you want, not I have removed empty columns from the database - a database should be a continuous table with no empty rows or columns.
    Attached Files Attached Files
    Last edited by royUK; 06-18-2009 at 09:32 AM.

  10. #10
    Registered User
    Join Date
    06-16-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Matching patient personal data to that already stored in a database

    Hi

    The file you attached in the last post seems to be exactly the same as the original i sent you....

    Helen

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Matching patient personal data to that already stored in a database

    I've re-uploaded the example.

  12. #12
    Registered User
    Join Date
    06-16-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Matching patient personal data to that already stored in a database

    Thanks very much.
    Will have a look at it and hopefully it will do the trick!

    Helen

  13. #13
    Registered User
    Join Date
    06-16-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Matching patient personal data to that already stored in a database

    Thank you RoyUK for all your help.
    I managed to edit the code you sent me for inclusion in my original workbook and it all works perfectly.

    I didn't really know anything about VBA this time last week and have learnt quite a lot through getting things wrong!

    Thank you again for your help!

  14. #14
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Matching patient personal data to that already stored in a database

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1