Disable at load if...

equilib

Registered User.
Local time
Today, 14:04
Joined
Sep 21, 2009
Messages
19
Hi,
I have a strange problem. I'm importing data into a base and when I open a form I want to grey-out some checkboxes if other checkboxes are not ticked in the imported data.

I use the onload event and type a simple code:
Private Sub Form_Load()
If Me.Quotas = No Then
Me.Capacity.Enabled = False
Else
Me.Capacity.Enabled = True
End If
End Sub

where Quotas and Capacity are checkboxes.

But this does not gray-out the box Capaciy when there is no tick in Quotas after loading the form. The strange thing is that the same code works fine if I put it in the after-update event for the Quota box and tick it on and of. But I want it to happen automatically at load.

What can be the problem?

Thanks,
Equilib
 
It would be:

Code:
Private Sub Form_Load()
   Me.Capacity.Enabled = Me.Quotas
End Sub
 
You probably also want the same code in the form's ON CURRENT event too.
 
It would be:

Code:
Private Sub Form_Load()
   Me.Capacity.Enabled = Me.Quotas
End Sub

Thanks for fast reply - but running that onload does not change anything in my form. Capacity remains enbled both when Quotas is checked and not checked...
 
Are you running Access 2007? Perhaps you need to do this.

And if that isn't it, perhaps you might upload a copy of the database (without sensitive info in it, of course).
 
Don't forget these controls can have triple state, True, False & Null. Therefore it may be more prudent to test if Not True, that way you capture both False and Null together.

David
 
Good Point!

Don't forget these controls can have triple state, True, False & Null. Therefore it may be more prudent to test if Not True, that way you capture both False and Null together.

David

Good - no, excellent point :)
 
Place the following code into your forms On Load and On Current events:-

Code:
If Me.Quotas = [B]-1[/B] Then
Me.Capacity.Enabled = True
Else
Me.Capacity.Enabled = False
End If

If you then require the ability to check the Quotas to enable the field manually, you need to place the same code into the Quotas After Update event.
 
Yes I run 2007 and updated the settings in the Trust centre but that did not change anything.

Here is a mini version of the base.

Structure:
It takes data in table "Basedata" that are selected on a few criterias and either appends the table "Cartelldata" or updates the ID in that table if the entry already exists there.

Problem:
Upon load of form Cartellinfo I would like to:
If "Pris" (price) is unchecked - disable the checkboxes Maxpris, Minpris and Marginaler.

So strange that the same function works at the update event but not at the forms load.

Thanks for having a go at it!

equilib
 

Attachments

Place the following code into your forms On Load and On Current events:-

Code:
If Me.Quotas = [B]-1[/B] Then
Me.Capacity.Enabled = True
Else
Me.Capacity.Enabled = False
End If
If you then require the ability to check the Quotas to enable the field manually, you need to place the same code into the Quotas After Update event.

Good point - but as I have set triple state to no in the properties I don't think it will do the trick. It neither explains why it works in afterupdate and not in onload.

Best,
Equilib
 
I just played around and On Load is the wrong place, it should be in the On Current only.

With On Load it appears to set the change for the whole form (i.e. all records) based on the value of the Quota check box in the first record.

Take the code from your On Load event and place it in your On Current event only (and maybe the After Update event of the Quota if you want to be able to check and enable/disable manually)
 
I just played around and On Load is the wrong place, it should be in the On Current only.

With On Load it appears to set the change for the whole form (i.e. all records) based on the value of the Quota check box in the first record.

Take the code from your On Load event and place it in your On Current event only (and maybe the After Update event of the Quota if you want to be able to check and enable/disable manually)

Great - I will try that right away!
I always thought you were suppose to load data events with On load so that you don't reload them all the time as you do with On Current. But I'll go with whatever works :-)

Thanks for your help
equilib
 

Users who are viewing this thread

Back
Top Bottom