[Access 2007] Trying to update a form field based on another field based on a query!

Glassify

New member
Local time
Today, 09:26
Joined
Oct 17, 2009
Messages
2
NEVERMIND: Solved by making the macro do "RunCommand: Refresh" before anything else :) Thanks for looking.

I'm using Access 2007. I am a complete beginner with anything related to coding with databases so please try not to confuse me too much. This is just for the prototype of a future school project, so ages used are just examples.

I have an appointments database, and patients can have different discounts for their appointments based on their age. What I am trying to do is have the discount type field in a form populate automatically based on the age of the person, which is calculated from the DOB entered. I can currently update the discount in the patient table itself, but I have to use three queries and the update does not actually show up on the form automatically! I just basically need a better/faster way to do this which means the DiscountType will still be STORED, but show up on the form automatically.

For example purposes, here is my patient table:
Patient ID
Name
Forename
DOB
Discount? Y/N
DiscountType

And the discount table:
DiscountType

I have a query in which I can calculate the age from the DOB using
Code:
Age: DateDiff("yyyy",[DOB],Now())+Int(Format(Now(),"mmdd")<Format([DOB],"mmdd"))
This means the age is automatically calculated when I enter the DOB into my form, which I've attached an example of.

And I want to have that discount type combo box automatically populate.

I have three update queries which updates the DiscountType in the Patient table upon entering the DOB and updating the age in a form based off that age query above, as I have a macro which is run after updating the DOB field which opens all three queries (which also requeries the discount type field, but it still won't update)

Updates Discount Type to "None" if the person is between 18 and 65.
Code:
UPDATE qryPatientAge INNER JOIN tblPatient ON qryPatientAge.PatientID = tblPatient.PatientID SET tblPatient.DiscountType = "None"
WHERE (((qryPatientAge.Age)>18 And (qryPatientAge.Age)<65));
Updates Discount Type to "Pensioner" if the person is over 65.
Code:
UPDATE qryPatientAge INNER JOIN tblPatient ON qryPatientAge.PatientID = tblPatient.PatientID SET tblPatient.DiscountType = "Pensioner"
WHERE (((qryPatientAge.Age)>65));
Updates Discount Type to "Student" if the person is under 18.
Code:
UPDATE qryPatientAge INNER JOIN tblPatient ON qryPatientAge.PatientID = tblPatient.PatientID SET tblPatient.DiscountType = "Student"
WHERE (((qryPatientAge.Age)<18));
Basically, is there a better way I can do this which will make the discount type show up in the form automatically? Thanks. Sorry if this is confusing!
 

Attachments

  • form example.gif
    form example.gif
    13.4 KB · Views: 406
Last edited:
NEVERMIND: Solved by making the macro do "RunCommand: Refresh" before anything else :) Thanks for looking.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom