locked
Fox pro check table for duplicate record using date RRS feed

  • Question

  • Hi there, basically I have anAM table and a PM table.

    I have 2 forms, one AM and one PM. There is a text box and a button which I use a click event.

    The text box is used to enter a numeric reading.

    When the button is clicked it saves the readings along with the date in the correct table.

    What I would like - when the button is clicked on either form, it checks the correct tables (Am or PM) for a duplicate value, so if the table contains a record with todays date then displays a message box and stops running the rest of the code.

    If there is not a record with todays date then carry on to the rest of the code which will save the record correctly.

    Also if for instance, they put in the wrong reading and then realised and tried to put in the correct reading ,the above message box will pop up and will give them the option to delete what is currently stored in the table and use the reading they just entered instead - which I suppose would work by just deleting the record with todays date and then run the rest of the code which will save the correct reading they have just entered.

    Any help on how to do this will be great. 

    Totally new to fox pro.

    Thanks

    Tuesday, January 22, 2013 4:25 PM

Answers

  • In this case the best way to go about it would be asking for the reading last, not before you search. Ask the user for the meter, then lookup a record for today, if found just position at this record and the user may or may not change the current reading value.

    So you're going about this in the wrong order, this just complicates things.

    The problem to find a record for today remains, you jsut would do it first. I assume your table(s) store date, reading, and a meter id or name, too. Or is it just readings of a single meter anyway?

    You want one reading per meeter per day. Tamar asked about the split in AM an PM table, I agree this is also questionable. Why seperate this? OIR do AM and PM have a different meaning?

    Having fields meter (char with a meter name), reading (numeric) and readdate (date), an index on DTOS(readdate)+meter Tag dayread will help you find a record of today of a certain meter by SEEK(DTOS(DATE())+"your meter","dayread","AM").

    If that returns .T. there is a reading and the record pointer in the AM table is then also positioned on that record. So you have the benefit the user will see the reading and may edit it. If not you can insert a new record and then let the user enter a reading into it.

    Bye, Olaf.


    • Edited by Olaf Doschke Wednesday, January 23, 2013 9:42 AM
    • Marked as answer by Youen Zen Monday, January 28, 2013 9:34 AM
    Wednesday, January 23, 2013 9:40 AM

All replies

  • I can't imagine what you're tracking that you need separate tables for AM and PM. So I think the first you need to do is explain what you're trying to do here.

    The right way to handle time is to use DATETIME fields, which track date and time, including AM/PM.

    Tamar

    Tuesday, January 22, 2013 9:46 PM
    Answerer
  • We need to store water metre readings.

    Yes I have it storing date & the time.

    As said previously, all I need, on button click, check the am table to see if a reading exists already with todays date. So if one person entered a reading, then an hour later someone else tried it on the same day it would flag up a message saying " A reading has already been entered " then it would display the reading that is stored in the table and ask if this should be deleted and the new reading added.

    thanks

    Wednesday, January 23, 2013 9:01 AM
  • In this case the best way to go about it would be asking for the reading last, not before you search. Ask the user for the meter, then lookup a record for today, if found just position at this record and the user may or may not change the current reading value.

    So you're going about this in the wrong order, this just complicates things.

    The problem to find a record for today remains, you jsut would do it first. I assume your table(s) store date, reading, and a meter id or name, too. Or is it just readings of a single meter anyway?

    You want one reading per meeter per day. Tamar asked about the split in AM an PM table, I agree this is also questionable. Why seperate this? OIR do AM and PM have a different meaning?

    Having fields meter (char with a meter name), reading (numeric) and readdate (date), an index on DTOS(readdate)+meter Tag dayread will help you find a record of today of a certain meter by SEEK(DTOS(DATE())+"your meter","dayread","AM").

    If that returns .T. there is a reading and the record pointer in the AM table is then also positioned on that record. So you have the benefit the user will see the reading and may edit it. If not you can insert a new record and then let the user enter a reading into it.

    Bye, Olaf.


    • Edited by Olaf Doschke Wednesday, January 23, 2013 9:42 AM
    • Marked as answer by Youen Zen Monday, January 28, 2013 9:34 AM
    Wednesday, January 23, 2013 9:40 AM