Solved What is locking my form?

lacampeona

Registered User.
Local time
Today, 01:35
Joined
Dec 28, 2015
Messages
392
Hello experts

Recently I notice that sometimes my forms ( not all the forms) are locked and data entry in the form is set to No and some of my buttons are enabled?
Who is doing that? my vba code? :confused:

Ok I have to say yes I have some code on the current and and on the load event of the form , but here I have code to enable and disable some buttons?
What i am doing wrong? Did i trigger all that becouse my codes on current and load event?

Where is good to put the codes for enabled and disabled butttons? on current? on load? or another event?

What is the difference on load and the current event? I read something on the net but hmm is that almost the same?

I have to say that I didnt touch nothing and I put data entry to Yes? hmmm

Example: yesterday was all correct today the same form is locked and data entry is set to No and some of my buttons are enabled?

Does somebody have such a experience?

Sorry if this is maybe stupid question but I need to see your experience to correct my mistakes.

thanks in advance
 
The On Load event on fires wherever the form is first loaded. It fires after the initial Open event. Controls will have values.
The On Current event fires every time the current record is moved from. So everytime you move from one record to another.

In theory, the current event also fires after on form load when the current record finishes loading, but in my experience, this isn't always the case, depending on the way the form is set up.

Described in detail here - form and controls, the order of processing.
 
if you are using a .accdb (rather than .accde) perhaps you have some save code which is saving the form, rather than the record. So you open the form, some events disable your controls - then you save the form with those controls disabled
 
Hello
yes i am using a accdb. You mean is better to prepare accde for my users? Now they are testing in accdb?
Thanks for your suggestion
 
You mean is better to prepare accde for my users?
that's my preference - users cannot then mess with forms/reports and code. But it is up to you, I'm sure there are plenty of developers out there who provide .accdb's
 
If you open the query the form is bound to outside of the form, can you update the data. If not, it is the query that is causing the form too be not updateable. The most common reason is aggregation like Sum(). Max(). First(), etc
 
Hello
what exatly i have to do? Where i have to use Sum()? in the query?
can you show me some example ?
thank you
 
I have to say that I didnt touch nothing and I put data entry to Yes? hmmm
If you have code that disables controls, why not step through and see what's happening? Maybe post the code that is disabling controls and explain why you are disabling them.
 
@lacampeona
Have you tried to open the query outside of the form? Can you update the records that way? We really can't move further without knowing whether the problem is with the query or the form.
 
Hello everybody
sorry for late reply I was very busy.
Yes I will try your suggestion about query and checking all my code.
thank you
 
Hello Pat, I was reading again your suggestion about
I am thinking what you say...

The most common reason is aggregation like Sum(). Max(). First(), etc
Yes I have one field that is calculating some sum...I have that field on the form. Is not part of the table. Is special field to inform user for some sum numbers.
Have you tried to open the query outside of the form?
What exatly you mean with that? How I test that? Which query I have to open?
hmmmm :unsure:
 
Assuming it is a stored query, you would see that query in the Navigation panel on the left side and can simply open it directly. Now some queries are depended on the form being open when you do this if there are controls on the form involved. Usually the query will just be based of tables and you enter in parameters if necessary and it just opens up in a datasheet view. Pat was just asking if you can open it directly from the nav pane.
 
Hello
thank you. Now I understand what Pat was saying.
I dont have query to calculate my special field for sum?
I have field (text field) on top of the form which is calculating my sum. hmmmm
 
CAN YOU UPDATE the data in the query? It is ever so much easier for us to help you if you try to answer EACH question.
 
Thank you. Now we know that the problem is with the form. Code that depends on data values belongs in the form's Current event. Only something that would NEVER change once the form is open belongs in the form's Open event since the Open event runs only once. If you can post the database with instructions of how to see the problem, that would be easiest. Make sure to remove or obscure any sensitive data.
 
Hello, thank you for your suggestion.
Well yes I will post the database but first I have to find the forms becouse sometimes is locked and sometimes not. I have various forms and sometimes are locked 2 forms and sometimes only one.
I will do testing in coming days and when I will notice the problem again I will put the database.
thank you
and sorry if i was complicating evertying when you just need simple answer. I am strange :oops:
 
Hi again
i am back. Meantime I was testing some another problems.
I have a code in my load form event that if the record is signed ( null, entered or apptoved) the fields on the form and some controls get enabled or disabled.
It is possible that is making my problems? Sometimes the data entry on the forms is set to No and sometimes all the fields and controls are disabled.

So is that correct? shall I put that such a codes on the On Current event? Or on the open? or load?

thank you



Private Sub Form_Load()

If IsNull(Me.status) Then 'the record IS NEW
Me.btnApprove.Enabled = False
Me.btnPodpisi.Enabled = True
Me.OpombePregledovalec.Enabled = False
Me.btnKopirajZapis.Enabled = True
ElseIf Me.status = "entered" Then
Me.btnApprove.Enabled = True
Me.btnPodpisi.Enabled = False
Me.StaraOznakaKolone.Enabled = False
Me.DatumPrispetja.Enabled = False
Me.NazivKolone.Enabled = False
Me.Proizvajalec.Enabled = False
Me.SerijskaStevilka.Enabled = False
Me.KataloskaStevilka.Enabled = False
Me.LotNo.Enabled = False
Me.Dolzina_mm.Enabled = False
Me.Premer_mm.Enabled = False
Me.VelikostDelcev_um.Enabled = False
Me.OddelekLastnik.Enabled = False
Me.SistemKolone.Enabled = False
Me.StatusKolone.Enabled = False
Me.OpombeIzvajalec.Enabled = False
Me.OpombePregledovalec.Enabled = True
Me.btnKopirajZapis.Enabled = False
Me.btnNovZapis.Enabled = False
Me.btnDodajAnalCertifikat.Enabled = False
ElseIf Me.status = "approved" Then
Me.btnApprove.Enabled = False
Me.btnPodpisi.Enabled = False
Me.StaraOznakaKolone.Enabled = False
Me.DatumPrispetja.Enabled = False
Me.NazivKolone.Enabled = False
Me.Proizvajalec.Enabled = False
Me.SerijskaStevilka.Enabled = False
Me.KataloskaStevilka.Enabled = False
Me.LotNo.Enabled = False
Me.Dolzina_mm.Enabled = False
Me.Premer_mm.Enabled = False
Me.VelikostDelcev_um.Enabled = False
Me.OddelekLastnik.Enabled = False
Me.SistemKolone.Enabled = False
Me.StatusKolone.Enabled = False
Me.OpombeIzvajalec.Enabled = False
Me.OpombePregledovalec.Enabled = False
Me.btnDodajAnalCertifikat.Enabled = False
Me.btnKopirajZapis.Enabled = False
Me.btnNovZapis.Enabled = True
End If
 
So is that correct? shall I put that such a codes on the On Current event? Or on the open? or load?

If you wanted to allow or disallow editing on a per-record basis, the Form_Current event IS the place to set the form's AllowEdits to YES or NO as appropriate to your record's "Signed" indicator or whatever other field is your controlling indicator. Just remember to set AllowEdit to YES or NO as appropriate to the record status for EVERY record.

You should not set or clear AllowEdit in the Form_Open or Form_Load routine if you were going to do so in the _Current event routine. In that case, changing the AllowEdit in three places is overkill. Only for _Current would it make sense. You would probably use the _Load event for an unbound form since unbound forms don't have a _Current event. Doing something to controls in the _Open event doesn't work because controls don't get loaded until the _Load event.

However, using AllowEdit is like using a sledgehammer to kill a fly. If what you want is SELECTIVE locking of controls, AllowEdit is not the way to do it. Instead, you would have to visit every control that you wanted to lock or unlock based on whatever is your decision basis. That would ALSO likely go in the _Current routine.

The third possibility is if a given control's content SHOULD dynamically change the state of other controls. In that case, you typically put code in the critical control's _LostFocus or _Change or _Click event (depending on what it was) so that you could change the states of the other controls just after you change the state of that critical control.
 
Hi again
i am back. Meantime I was testing some another problems.
I have a code in my load form event that if the record is signed ( null, entered or apptoved) the fields on the form and some controls get enabled or disabled.
It is possible that is making my problems? Sometimes the data entry on the forms is set to No and sometimes all the fields and controls are disabled.

So is that correct? shall I put that such a codes on the On Current event? Or on the open? or load?
Hi, if the setting of some form controls changes from one record to another you should use the Current event. As for settings differentiating between new and existing records I prefer using the NewRecord property, i.e.
Code:
If Me.NewRecord Then
   ...
Else
   ...
Endif

Best,
Jiri
 

Users who are viewing this thread

Back
Top Bottom