Solved Detect the active field and its value (1 Viewer)

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:38
Joined
Feb 19, 2002
Messages
43,275
You should be thanking CJ not me. He gave you a suggestion that let you use a button. Relying on the user to press a button to make a mandatory process happen is just poor practice. What are the consequences if the user fails to remember to press the button? When will you discover that the tables are out of sync?
 

zelarra821

Registered User.
Local time
Today, 12:38
Joined
Jan 14, 2019
Messages
813
The issue is that I only want the button so that when it is in the oil type field the user can, through a series of inputboxes, add a price and a date, which will be saved in the table. I don't know if I can convey what I want to do. The subform table is not synchronized at all. Where it is saved is in a third table that has nothing to do with a main form and the subform. Do you get my idea?

Thanks to CJ and everyone who, at some point throughout the history of this thread, has been able to participate. Really thank you very much.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:38
Joined
Feb 19, 2002
Messages
43,275
Do you get my idea?
I get your idea and I knew instinctively that your "solution" was flawed. I tried to convey that there are ways to do this that do not involve buttons. As I said, YOU decided what the solution was. You chose to not describe the problem. You started this thread KNOWING what your solution was and only needed advice on how to implement it. Therefore, you got a rote answer that doesn't actually solve the problem. It just looks like it works because it works if everyone does everything correctly AND it also only works for the first record in the subform because the button is on the main form and not on the subform. The tag property gets set but it is set for EVERY row because the tag is a property of the FORM, not the RECORD. But your original solution was never optimal and is in fact dangerous in that it relies on the user to remember to do the right thing.

It is only because I persisted AFTER you had a "solution" that we are now at the point where we have a clearer understanding of the problem and are not trying to implement your incorrect solution.

Remove the button. A separate button is not appropriate for this process.
In the subform's BeforeUpdate event, you check the type field. If it is oil, you can check to see if the other required fields are present. If they are not, you can use
Cancel = True to prevent Access from saving the incomplete record and go back and fill in the missing data.

BUT, you still are saying that this data needs to be added to a separate table. The question now becomes - WHY? Why if every new record requires a new pricing record is that pricing data separate? If the price can never be reused, then it doesn't belong in a separate table.

Without that clarification, the suggested solution is still incomplete so there is no point in even providing air code.
 

zelarra821

Registered User.
Local time
Today, 12:38
Joined
Jan 14, 2019
Messages
813
You're going to excuse me, but in the end the button wasn't necessary. I was recording a video to show you how it works when I realized the error.

Thank you very much for your clarifications.

Anyway, I'll explain what I've done with another example that does apply:

I have a form where the hours of work on each property of a worker, vehicle and tools are collected.

There are no subforms in that form.

There is a button to add labor, vehicle and implement prices.

I have four tables: one with the records of the hours, and another with the prices of labor, vehicles and tools.

With a Select Case, I detect the active field and if it corresponds to one of those that I can set a price, I insert the date and price that the user has added in the inputboxes. That way, it's faster than having to go to another table to add it.

That said, thank you very much.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:38
Joined
Feb 19, 2002
Messages
43,275
With a Select Case, I detect the active field and if it corresponds to one of those that I can set a price, I insert the date and price that the user has added in the inputboxes. That way, it's faster than having to go to another table to add it.
Still makes no sense. Test verrrrrrrry carefully.

Good luck.
With a Select Case, I detect the active field
Not possible. The active field is the button. If you are using the tag property on multiple controls, then multiple controls could have the tag property set. The select case would identify the first tag only.
 

Users who are viewing this thread

Top Bottom