Link to home
Start Free TrialLog in
Avatar of BFanguy
BFanguyFlag for United States of America

asked on

Access 2010 Form OnPaint Event problems with me.xxx.value on continuous subform if has New Record (allowinserts)

I am trying to hide a button on a continuous subform if me.action = 5

Private Sub Detail_Paint()
me.mybutton.visible = False

   If Not IsNull(Me.Action) Then ' this is somehow true on the new record >* ????
      If Me.Action = 5 Then
         me.mybutton.visible = False
      End If      
   End If

End Sub

Open in new window


If i open my subform as allow inserts = false it works fine.
if there is a >* record it fails stating that me.action can't find  run-time error 2424

is there a way to test to see if I am on a >* record - testing for not IsNull on one of the fields evidently does not work.

any help is appreciated
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Try it on the current even instead.

You will also have to add the same code to the After Update event of the "me.action" control...
Avatar of BFanguy

ASKER

If i do this on current it changes for all records on the continuous form.

i.e. if record 2 on my subform has a action of 5 all records on the subform show the button.

i only want the button to show when the action = 5 on the record.
Avatar of BFanguy

ASKER

Let me clarify.
10 records display on the continuous subform.  
button set to visible = false
2 have action = 5.

if i click on a record that has a action = 5 all 10 records show the button
if i click on a record that does not have a action = 5 none show the button.
This may not be easy on a continuous form...
What I typically do is put the button in the form header (not the detail section)
...This way you only really have "one" button to deal with, ...then the current event and after Update evens should work fine.

Having a button on each line looks great until you need to do something like hiding the button for certain conditions. (which, as you see here, ...is not easy on a continuous form)


What you could do is just throw a message if they click the button:
If Me.Action = 5 Then
         msgbox "Action is: " & me.Action & ". So you cant do this now"
End If      

Or use conditional formatting in the detail section if the value of Me.Action is 5.

JeffCoachman
like so, (on each control, set the the rule/condition to: Action=5, and set the background color to red)
User generated image
Avatar of BFanguy

ASKER

When i open my continuous subform in design view and no matter where i click the Conditional formatting is grayed out.  Tried the form, detail section, controls...
Conditional formatting only works with "controls" in a section, ...not on the section (backcolor) itself.
I apologize for not making that clear in my post.
User generated image

But the the screenshot I posted shows the conditional formatting in effect on the textbox controls when Action=5...
Avatar of BFanguy

ASKER

ok.  so evidently conditional formatting does not work on buttons..
it's a button i am trying to hide based on the value in a control.
is this possible?

thanks for all of your help.
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BFanguy

ASKER

Thank you for your help!
Thanks
Glad I could help.