Make a control visible when record is loaded

pretogues

New member
Local time
Today, 04:11
Joined
Aug 25, 2012
Messages
7
Hi.

As I told in my first post, I'm trying to re-learning to work on Access.
I need to do it because I have to build a project in my job.

This is my question (please, don't get me wrong, but my english is not quite good!):
I have build a form with to combo boxes: in the fist one I have 5 records; in then second one, I have 3.

I reached to make a filter between the two combo boxes, I mean, when the third option of the first combo is choosen, the second combo turns visible. I made this with the event procedure "after update". This is the VBA coomand:

Private Sub Caixa_de_combinação28_AfterUpdate()
If Me![Caixa de combinação28].Text = "Execução" Then
Me![Caixa de combinação30].Visible = True
Else
Me![Caixa de combinação30].Visible = False
End If

Me![Caixa de combinação30].Requery
End Sub


"Caixa de combinação28" is the first combo;
"Execução" is the third option - the one that makes visible the second combo;
"Caixa de combinação30" is the second combo

My question is: when I open the form, and it has some records already, if one of them has the third option choosed on the first combo box, I want to make the second one visible when i load this record. I mean, in this case, the second combo would be already visible, because when the record is loaded, the first combo has the third option.

I think this must be a little confuse!!! Sorry!!!

Thanks for your support.
Best regards,
Pedro
 
Have the same piece of code in the Form_Current() method..
something like..
Code:
Private Sub [COLOR=Red]Form_Current[/COLOR]()
[I]If Me![Caixa de combinação28].Text = "Execução" Then
Me![Caixa de combinação30].Visible = True
Else
Me![Caixa de combinação30].Visible = False
End If

Me![Caixa de combinação30].Requery
[/I]End Sub
 
Hi, again.

I've tried that on the "Current" form procedure, but there is an error msg like this: "It's only possible to refer to a property control when it has the focus".

Well, i understand that because i have another control in that form that is the first to get the focus. What i have to do to give the focus to the fist combo?

Thanks for your support.
 
Hmmm.. try a dot(.) operator instead of a Bang(!)..
Code:
Private Sub Form_Current()
    If Me.[Caixa de combinação28].Text = "Execução" Then
        Me.[Caixa de combinação30].Visible = True
    Else
        Me.[Caixa de combinação30].Visible = False
    End If
    Me.[Caixa de combinação30].Requery
End Sub
 
Hi, again.

When i try with the dot, it gives the same error msg (number 2185).

i wonder if makes any sense to move the statement of the "requery" to another place like inside the "if" sentence. But I've tryed too and gives the same error either...
 
Can you show me your code.. and the exact error description..??
 
Hi.

The code is this:
Private Sub Caixa_de_combinação28_AfterUpdate()
If Me.[Caixa de combinação28].Text = "Execução" Then
Me.[Caixa de combinação30].Visible = True
Else
Me.[Caixa de combinação30].Visible = False
End If
Me.[Caixa de combinação30].Requery
End Sub


And for the forms "Current" procedure is exactly the same.

The msg error says in portuguese: "Run-Time error 2185: It's only possible to reference a property or method of a control when this one has the focus".

Thanks for your support.
 
The error msg give you the answer, the .Text property is only available when the control has focus which it does not in the AfterUpdate event, use the Default .Value property instead.

Code:
[I]Private Sub Caixa_de_combinação28_AfterUpdate()[/I]
[I]If Me.[Caixa de combinação28].[COLOR=red]Value[/COLOR]= "Execução" Then[/I]
[I]Me.[Caixa de combinação30].Visible = True[/I]
[I]Else[/I]
[I]Me.[Caixa de combinação30].Visible = False[/I]
[I]End If[/I]
[I]End Sub[/I]

How ever since the .Visible property is only True or False you can do a directly boolean comparison, I think this should work also:

Code:
[I]Me.[Caixa de combinação30].Visible = (Me.[Caixa de combinação28].[COLOR=red]Value [/COLOR]= "Execução")[/I]

JR
 
Well, I think it works!!!

I put a msgbox to get the value of the combo on "current form" and it gave "3", not "Execução" (that was the record associated to ID 3). Now i changed the "value" to 3 and it worked!!!

Thank you very much for your support and i'm very sorry for this stuff, I'm trying to re-learning...
 

Users who are viewing this thread

Back
Top Bottom