Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AfterUpdate Event Procedure Error 4

Status
Not open for further replies.

eagle11232

Technical User
May 13, 2008
11
0
0
US
In a single form I have one dropdown field that is a yes/no option, based on the input, in this case a no, I want to either lock out or simply hide the following four fields (3 dropdowns and one text). I checked the FAQ and searched the forum, but didn't find anything that helped me. I have never coded VB before, so if someone can tell me where my error is it would be greatly appriciated. Thanks

Private Sub Label77_AfterUpdate()

Dim Label77 As Boolean
If FormTestOne.Label77.Value = False Then FormTestOne.Extra1.Dropdown.visable = False
End If
End Sub
 
Are you creating a boolean variable with the same name as your control? BTW, visible is not spelled correctly.

RuralGuy (RG for short) aka Allan Bunch MS Access MVP acXP winXP Pro
Please respond to this forum so all may benefit
 
Its a Runtime 424 Error Object. I will change the spelling of visible when I get to my computer (sent this from my phone) Thanks guys
 
How are ya Eagle11232,

Try this

Private Sub Label77_AfterUpdate()

If (Me!Label77.Value) = False Then
Me!Combo1.Visible = False
Me!Comob2.Visible = False
Me!Combo3.Visible = False
Me!Text1.Visible = False
End If

If (Me!Label77.Value) = True Then
Me!Combo1.Visible = True
Me!Combo2.Visible = True
Me!Combo3.Visible = True
Me!Text1.Visible = True
End If

End Sub

Regards,
Nim
 
Thank you all for the help. I have put the code in that Nim suggested, yet I am still getting a 424 Error. My best guess is I don't fully understand how VB associates file names and such.

If I correctly understand the code that Nim provided, Me! refers to the form name that I am using. If the name of the form is Form Test One, do I code it as such, or FormTestOne/Form_Test_One or something else.

Additionally, for Combo1.Visible or Text1.Visible, do the same rules apply? For instance, the first combo box is called label77 when I view the properties of the box.

Thanks again for all the help.
 
Yes "Me" can be used in place of the current object, and in fact you can not reference the form like you did solely by its name. You could call it like this using the forms collection
1) forms("FormTestOne")
or
2) forms!FrmTestOne
or you can use the form class (not usually done)
1) Form_FormTestOne

but within a form/report you can refer to the current form/report with "Me"

the first combo box is called label77

Now, I have seen some bad naming conventions, but that takes it for confusion. That would be like calling a table "tblEmployees" and filling it with information about Animals.

how about naming it "cmboShowFields"

same with your other combos. Give it a name that tells the code reader (yourself) what is going on.
not combo1 but comboPeopleNames


Looking at the error I do not think it is in Nims code. Where is it breaking?
 
Now your original post will most certainly give an "object required" error

If FormTestOne.Label77.Value = False Then FormTestOne.Extra1.Dropdown.visable = False

Because as I said you can not refer to a form or report by solely its name. So you are not returning an object, but then you try to call methods and other properties for an object that does not exist and thus.
"object required" error
 
I would also suspect that the ComboBox Value is not a Boolean value so this test:
FormTestOne.Label77.Value = False
...is suspect.

RuralGuy (RG for short) aka Allan Bunch MS Access MVP acXP winXP Pro
Please respond to this forum so all may benefit
 
RuralGuy,
Actually I think in vb you could get away with it (assuming all of the other issues were fixed.)

Code:
Public Sub Test()
  Dim x As Boolean
  Dim y As String
  Dim z As String
  x = False
  y = "False"
  z = "True"
  Debug.Print x = y
  Debug.Print x = z
End Sub

output:
True
False
 
I should have expressed myself better. True for Access is simply a non zero value and false is zero. I question whether the Label77 ComboBox is actually bound to a Boolean column. I suspect not and this is not working the way the OP wants but sort of works anyway. Of course we still have thet error! ;)

RuralGuy (RG for short) aka Allan Bunch MS Access MVP acXP winXP Pro
Please respond to this forum so all may benefit
 
hey eagle,

When you get the error what line does it point to in the code? The code i have given should work fine, im guessing you havent placed the right name for each combobox and textbox into the code. Label77 refers to your dropdown with the yes/no value. You need to put the code into the afterupdate event of this combobox. Combo1-3 refers to the name of your 3 other comboboxes on the form which you want to show/hide. Text1 refers to the name of your textbox. Just fill in the that information and it should work.

Nim
 
Thank you all for all of your assistance thus far. I have been able to update the code so that it runs, however, I am not seeing the results I expected; namely, when the test is false, the other fields are still visible and available to input data.

As MajP correctly stated in one of the earlier posts, the naming convention of label77 being poor, I completely agree. If there is in fact an award for the most poorly chosen label, I request to be entered as I think I could win it. :)

I used the wizard to create the basic outline of my form and modified it from there. As such, I don't believe I fully understand how to correctly change the labels as my first attempt resulted in an Invalid Control Property: Control Source error.

In design view, when I open the properties of the label for the field or combo box, the name entry is what I assume VB uses as the variable name, and the caption entry is what is displayed on the form. Similarly, for the properties of the field or combo box, the name entry is what I assume VB uses as the variable name and the control source refers to the label.

Regarding the question from Rural Guy about whether or not the initial test is a Boolean variable makes me ask if that declaration can/is made in the design view under properties or a line of code somewhere.

Thank you again for all of your help
 
We might be able to better understand your ComboBox if you will tell us what the values are for the RowSourceType and the RowSource, which are on the data tab of the properties sheet for the control.

RuralGuy (RG for short) aka Allan Bunch MS Access MVP acXP winXP Pro
Please respond to this forum so all may benefit
 
How are ya eagle11232 . . .

I've not seen control names stipulated here except for [blue]Label77[/blue]. To get the [blue]actual names used[/blue] in VBA for any control:
[ol][li]Open the form in design view, then call up the properties window by clicking the properties toolbar button
Properties.BMP
(if the properties window isn't already open).[/li]
[li]Select the [blue]Other[/blue] tab. At the top of the tab you should see the [blue]Name[/blue] property. This is the name used by VBA for any control you select in design view.[/li]
[li]Now select those controls and get the names.

Note: in VBA any names including spaces have to be surrounded by brackets. Example:
Code:
[blue]   Me!Main Acct
[purple]should be[/purple]
   Me![Main Acct][/blue]
[/li][/ol]
Now that names are correct, we have to take care of the datatype of your yes/no combobox. Either you used a checkbox or you typed in the literals "True", "False".
[ol][li]If you used a checkbox in the combo, try:
Code:
[blue]   Dim flg As Boolean
   
   [b]flg = CBool(Me![[purple][i]YesNoComboboxName[/i][/purple]].Column(0))[/b]
   
   Me![[purple][B][I]ComboboxName1[/I][/B][/purple]].Visible = flg
   Me![[purple][B][I]ComboboxName2[/I][/B][/purple]].Visible = flg
   Me![[purple][B][I]ComboboxName3[/I][/B][/purple]].Visible = flg
   Me![[purple][B][I]TextboxName1[/I][/B][/purple]].Visible = flg[/blue]
[/li]
[li]If you typed in literals:
[code
Code:
[blue]   Dim flg As Boolean
   
   [b]flg = (Me![[purple][i]YesNoComboboxName[/i][/purple]].Column(0) = "True")[/b]
   
   Me![[purple][B][I]ComboboxName1[/I][/B][/purple]].Visible = flg
   Me![[purple][B][I]ComboboxName2[/I][/B][/purple]].Visible = flg
   Me![[purple][B][I]ComboboxName3[/I][/B][/purple]].Visible = flg
   Me![[purple][B][I]TextboxName1[/I][/B][/purple]].Visible = flg[/blue]
[/li][/ol]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Go to the control of each combobox and textbox and place put visible = false.
 
Success! Works like a charm. Thank you all for your patience and help with this issue. I can tell you that I am impressed by the knowledge of each of you as well as the forum as a whole. There are very few forums out there where the new guy can post a question and receive so much help, so quickly. Thank you again.
 
eagle11232 . . .

I hadn't checked your profile, so here's an official welcome to [blue]Tek-Tips[/blue]. Be sure to go over one of the links at the bottom of my post. It'll help you structure your questions better and give insight into etiquette here in the forums . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top