codes in forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have used the following codes to create a new question in a form when the
"yes" checkbox option was chosen:
Dim YesAnswer As Boolean
YesAnswer = MsgBox ("my question", vbYesNo) = vbYes
Me.1stControlToSeeWhenYes.Visible = YesAnswer
Me.2ndControlToSeeWhenYes.Visible = YesAnswer
Me.1stControlToSeeWhenNo.Visible = Not YesAnswer
Me.2ndControlToSeeWhenNo.Visible = Not YesAnswer

and I found out that it that does not work; the afterupdate does not accept
it, it does not accept ".1st"
What I should I do to create a set of new question when the answer yes is
chosen?
When I also change the format al ittle bit like:
MeFirstControlToSeeWhenYes.Visible = YesAnswer

I get the error 424 and the message "object required"
 
The first problem you have is naming. A name can contain numbers, but it
must start with a letter. Try changing the name of your control from
1stControlToSeeWhenYes to ControlToSeeWhenYes1.
 
Katluu:
I tried your way, but it did not work. I also used the followings:
ControlToSeeWhenYes1
ControlToSeeWhenYesFirst
ControlToSeeWhenYes1st
but I get the message "method or data member not found. Is there another way
that you may suggest?
Thanks
 
I am not sure what your problem is. Are you using Me.ControlToSeeWhenYes1?
Usually when you get that error, it means there is an ambiguous reference.
It is possible this control is on a sub form?
 
Klatuu:
Yes I'm using Me.ControlToSeeWhenYes1. The following is the set of codes
that I'm using:
Dim YesAnswer As Boolean
YesAnswer = MsgBox("my question", vbYesNo) = vbYes
Me.ControlToSeeWhenYes1.Visible = YesAnswer
Me.ControlToSeeWhenYes2.Visible = YesAnswer
Me.ControlToSeeWhenNo1.Visible = Not YesAnswer
Me.ControlToSeeWhenNo2.Visible = Not YesAnswer

for some reason is not working. What do you mean in a sub-form?
Is there a possible way to create a set of questions after choosing the
"yes" answer
like going to expression builder instead of going to codes?
 
Katluu:
This is what I have in code:
Private Sub "myquestion"AfterUpdate()
Dim YesAnswer As Boolean
YesAnswer = MsgBox("myquestion", vbYesNo) = vbYes
Me.ControlToSeeWhenYes1.Visible = YesAnswer
Me.ControlToSeeWhenYes2.Visible = YesAnswer
Me.ControlToSeeWhenNo1.Visible = Not YesAnswer
Me.ControlToSeeWhenNo2.Visible = Not YesAnswer
End Sub
But it does not work
What I want to do is to create only one question when the choise "yes" is
chosen. In other words, if "yes" is selected from the checkbox I want a
question to appear, that's all. Thanks
 
Maybe try this?

---
Code:
---
Dim YesAnswer As Boolean
Dim intAnswer as Integer
intAnswer = MsgBox("my question", vbYesNo)

If intAnswer = 6 Then 'in vbYesNo, Yes = 6
YesAnswer = True
Else ' No = 6
YesAnswer = False
End If

Me.ControlToSeeWhenYes1.Visible = YesAnswer
Me.ControlToSeeWhenYes2.Visible = YesAnswer
Me.ControlToSeeWhenNo1.Visible = Not YesAnswer
Me.ControlToSeeWhenNo2.Visible = Not YesAnswer

---[end code]---

I could be wrong but I think the problem is that you in vbYesNo Yes = 6 and
No = 7, they are not true/false booleans.

ggggeo
 
Back
Top