Change Visible Property in VBA


Joined
Jul 23, 2012
Messages
8
Reaction score
0
I'm working with MS Access at the moment and I'm having a problem getting a VBA script to fire. I think that the code is correct but when I test it nothing is happening. I am trying to make a text box disappear it the value of a combo box. The combo box has two values possible, Yes and No. If the Value is Yes I want the text box to disappear. I'm not really sure what I am doing wrong here but I really need help. I've done this before a few years ago, but either something has changed or I'm out of practice.

Here is the code that I am using.

Private Sub cmb_prt_spec_ac_AfterUpdate()
If cmb_prt_spec_ac.Value = "Yes" Then txt_spec_ac.Visible = False

End Sub

In the properties box for the combo box in the AfterUpdate space I have = [cmb_prt_spec_ac] and that should fire the VBA script, but thus far I'm not getting any results. I'm really thinking that I have just missed something stupid here and I'll be kicking myself in the butt as soon as I figure it out.
 
Ad

Advertisements

Joined
Jun 12, 2012
Messages
53
Reaction score
0
In the properties box for the combo box in the AfterUpdate space I have = [cmb_prt_spec_ac] and that should fire the VBA script
I think that here's the problem. You should have there something like "Event procedure" or something like that (I don't have english version of Access installed, so I'm guessing). When you click little triangle at the end of that field, it should be listed - please choose it. Then when you click on the "..." button (at the very end of that field) in design mode, you should be redirected to the cmb_prt_spec_ac_AfterUpdate() procedure in the code module.
When you'll achieve this, your application should work fine in runtime also :thumb:
 
Last edited:
Joined
Jul 24, 2012
Messages
3
Reaction score
0
I'm working with MS Access at the moment and I'm having a problem getting a VBA script to fire. I think that the code is correct but when I test it nothing is happening. I am trying to make a text box disappear it the value of a combo box. The combo box has two values possible, Yes and No. If the Value is Yes I want the text box to disappear. I'm not really sure what I am doing wrong here but I really need help. I've done this before a few years ago, but either something has changed or I'm out of practice.

Here is the code that I am using.

Private Sub cmb_prt_spec_ac_AfterUpdate()
If cmb_prt_spec_ac.Value = "Yes" Then txt_spec_ac.Visible = False

End Sub

In the properties box for the combo box in the AfterUpdate space I have = [cmb_prt_spec_ac] and that should fire the VBA script, but thus far I'm not getting any results. I'm really thinking that I have just missed something stupid here and I'll be kicking myself in the butt as soon as I figure it out.
I don't know wright script or how to enter it correctly?:blush:
 
Joined
Jul 23, 2012
Messages
8
Reaction score
0
Ok so I now have Event Procedure in the Properties list and still I am getting no responce from the form. I even went as far as to abandon that form and work with a test form in the mean time. On the test form I have a simple label and a check box. What I am trying to do is to get the label background color to turn red when the check box is selected. I'm not sure why I'm not getting the result that I want.

I am using the On Click Event to fire the code which is listed below. If anyone can tell me if the code is correct or not, (which I believe that it is) it would go a long way toward telling me where I am going wrong.

Private Sub Check1_Click()

If Check1.Value = "True" Then
Label0.BackColor = "#ED1C24"
Else
Label0.BackColor = "#FFFFFF"
End If

End Sub

Not really sure why nothing is working, but I'm sure that it is something stupid that I am missing.
 
Joined
Jun 12, 2012
Messages
53
Reaction score
0
Now you've messed it up a bit ;)
You can't use hex codes to assign color in VBA. Use long number or vb constants.
If you still desperately need to set the color in hexadecimal code use this function.
 
Joined
Jun 12, 2012
Messages
53
Reaction score
0
And there's more. I tested your code with above corrections and it still doesn't work. First thing: Check1.Value is never "True". It doesn't make too much sense, but it is -1 when checked and 0 when unchecked (!).
Second: changing the background color doesn't take any effect on the form view. I checked that the value is changed but new color is not visible. Don't ask me why :blush:
Moreover when you are changing the forecolor property it works as it suppose to :(
Here's some code that demonstrates all above:

Private Sub Check1_Click()

If Check1.Value = 0 Then
Label0.BackColor = vbGreen
Label0.ForeColor = vbRed
Else
Label0.BackColor = vbRed
Label0.ForeColor = vbGreen
End If

Label0.Caption = Check1.Value

End Sub
 
Last edited:
Ad

Advertisements

Joined
Jul 23, 2012
Messages
8
Reaction score
0
I actually fixed both problems. Took me a bit but I have it working now. Thanks for the help.
 
Joined
Jun 12, 2012
Messages
53
Reaction score
0
Good to see that you've managed. What you mean by "both" problems? Can you change the BackColor now? Please share with us. I thought that it's natural when you're posting on forum :confused:
 
Ad

Advertisements

Joined
Jul 23, 2012
Messages
8
Reaction score
0
yeah the problem wasn't really with my code. Once I got my head wrapped around the issue I discovered that the code for both the back color and visible properties worked just fine. The DBase has been corupted somehow. As soon as I started over, everything worked just fine. I was also able to solve a problem that I was having with checkboxes. I discovered that one of the key problems that I was having is that I was leaving the value qualifier off of the string.

I was writing,
If chk_box_1 = -1 then txt_prt_number.visible = True

what I needed was
If chk_box_1.Value = True Then txt_prt_number.Visible = True.

That worked just fine. The same worked for the conditional statements with the backcolor.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top