Click from another navigation (1 Viewer)

ilanray

Member
Local time
Today, 23:52
Joined
Jan 3, 2023
Messages
116
Hi
I have 2 navigation buttons.at the first navigation i have a torm with save button called SaveForm
I would like to click on the second navigationbutton and it will active the button SaveForm which is in the first button, how can i do it?
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:52
Joined
Sep 21, 2011
Messages
14,310
Me.SaveForm.Enabled = True. ???
 

ilanray

Member
Local time
Today, 23:52
Joined
Jan 3, 2023
Messages
116
No, i get an error message "method or data member not found
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:52
Joined
Sep 21, 2011
Messages
14,310
No, i get an error message "method or data member not found
Well the SaveForm part is meant to be the name of your button? :(

Me.TheNameOfYourActualButtonThatYouHaveForSavingTheForm.Enabled = True. ???
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:52
Joined
Feb 19, 2002
Messages
43,281
I would like to click on the second navigationbutton and it will active the button SaveForm which is in the first button, how can i do it?
If you mean that you want to run the code, just call the button's click event. It is like any other procedure.

Call Yourbuttonname_Click

PS, I don't like to call code in event procedures because it is easy to forget that the code is reused. So, instead, I would make a separate procedure and call that procedure from each click event so it is clear that the code is being reused.
 

ilanray

Member
Local time
Today, 23:52
Joined
Jan 3, 2023
Messages
116
I create a sub procedure called save_click_g() in form TaskForm. I create a button call this procudure
PHP:
public sub save_click()
        save_click_g
end sub
and it works greate

The problem I am talking about is, I have navigation tabs and inside i have the TaskForm with the sub procedure and the button
I have another form called xx , I created as you said the call procedure and I still get an error message "sub or function not defined"
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:52
Joined
May 7, 2009
Messages
19,245
you try to upload a sample db and describe again what need to be done.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:52
Joined
Feb 19, 2002
Messages
43,281
If you are using an actual Navigation form, only ONE subform is ever loaded at a time and so only the visible one is available. Therefore, you cannot reference any other subform.
 

ilanray

Member
Local time
Today, 23:52
Joined
Jan 3, 2023
Messages
116
So how do I go from one navigation to another without loosing all the data I wrote (in case I forgot to click save at the first form)?
 

GaP42

Active member
Local time
Tomorrow, 06:52
Joined
Apr 27, 2020
Messages
338
? When you add / edit data and move to another record access will save your data without an explicit save option, if the data conforms to the constraints defined for the table(s), or other constraints you might impose through vba. When you have "unsaved" data and select the other "navigation" ?? what happens - is the data lost?
If you find you need to save the data entered when you navigate, then invoke some vba on the navigate option (on click?) to tell access to save the data.
if you cannot do this then you need to provide a sample copy of your database (with non-sensitive data) and clearly describe what happens and what you want to happen
 

ilanray

Member
Local time
Today, 23:52
Joined
Jan 3, 2023
Messages
116
Hi
Attach an example, Please click on the "NAvigationMain" form. then add some data , don't click on save . just go to the next navigation tab. I would like to vba code will use the save command from the first form
 

Attachments

  • Database5.accdb
    1 MB · Views: 54

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:52
Joined
May 7, 2009
Messages
19,245
test this one.
note i copied all forms and tables to new db, since you have cyrillic alphabet on some of your controlnames.
 

Attachments

  • SAMPLE_EN1.accdb
    820 KB · Views: 67

ilanray

Member
Local time
Today, 23:52
Joined
Jan 3, 2023
Messages
116
so what you did is create click event to the second navigation tab . this is now what I mean. I would like to use the button from the first navigation tabs becuase at my original application I have a lot of logic in the save button and I can't ducplicated it
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:52
Joined
May 7, 2009
Messages
19,245
as mentioned before, when you click on another Tab, the subform will Close.
if you have lots of code, duplicate it on the Click event of the tab.
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:52
Joined
Sep 21, 2011
Messages
14,310
as mentioned before, when you click on another Tab, the subform will Close.
if you have lots of code, duplicate it on the Click event of the tab.
Or create a module and call that code from each event?
 

ilanray

Member
Local time
Today, 23:52
Joined
Jan 3, 2023
Messages
116
I tried to do it on a module . How can I call use the insert command on the module? I have to use something like [form]!... any syntax didn't go well
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:52
Joined
Feb 19, 2002
Messages
43,281
So how do I go from one navigation to another without loosing all the data I wrote (in case I forgot to click save at the first form)?
I have a lot of logic in the save button and I can't ducplicated it
Therein lies the problem. NO validation code belongs in the Save button. MOVE the validation code to the Form's BeforeUpdate event. Access will then automatically run the validation code when the form closes or moves focus to a different record. The save button should simply save the record. Once you tell Access to save the record OR Access decides all by itself that the record needs to be saved, Access runs the Form's BeforeUpdate event. That is where all you validation code belongs AND you need to use the Cancel = True whenever there is an error and you want to prevent Access from saving the record.

You are going to have to modify your code to get it to work well on a navigation form. For example, one of the problems will be that you will have to prevent the navigation from happening if an error is discovered in an automatic save.

You don't need to duplicate the code and in fact, that is a pretty poor idea. There are ways to get around this though. As someone mentioned, you can move the validation code to a standard module. To activate the code, you add a call to the procedure in the form's BeforeUpdate event and you can pass in a reference to the current form. As long as all the controls have the same name, this will work. HOWEVER, using this method, you cannot use Cancel = True to stop the save because that only works in the class module of a form. So, that would mean additional code changes.

It looks like your form is NOT an actual navigation form. We need to clear this up because it affects your solution. If each tab has a separate form on it and the forms are always loaded, you don't have the same problem you have with an actual Access navigation form and so the solution is different.

If this is a normal form with a tab control on it, you can add code that runs with the tab gets clicked. That code should just tell the other form to save the record. The code would look at the properties of the other form to determine if it is dirty. If it is dirty, then save. BUT - move all your validation code to the form's BeforUpdate event where it belongs so you can fix this the right way ONCE.
 

ilanray

Member
Local time
Today, 23:52
Joined
Jan 3, 2023
Messages
116
You just gave me an idea. I create an event on form_close(). so everytime the user will go from one form to another
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:52
Joined
Feb 19, 2002
Messages
43,281
But the subform doesn't close when you move from one tab to another --- UNLESS you are using an ACTUAL Access navigation form which you haven't confirmed.

The validation belongs in the Form's BeforeUpdate event (or if common code, is called from the BeforeUpdate event) no matter what else you change.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:52
Joined
May 7, 2009
Messages
19,245
the form is Unbound so BeforeUpdate (AferUpdate also) will not get triggered.
 

Users who are viewing this thread

Top Bottom