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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default state of controls when create a new record 2

Status
Not open for further replies.

dotolee

Technical User
Jan 27, 2008
134
CA
Hi there.
I have a form with different controls on it. it's essentially an electronic questionnaire.
There are cases where depending on how questions are answered, other controls on the page are hidden because they are no longer applicable. I have a lot of logic that looks something like:

if question1.value = 1 then
'hide question2
labelquestion2.visible=false
question2.visible = false
question2.value = NULL
else
'do the opposite of the above
end if

My question is, when i save a record where question2 (and possibly other questions) were hidden by the form, how do i get these controls to re-appear for the next record? I'm hoping that I don't have to write a function to set everything to visible again.
My thinking was that if by default, the controls' .visible property is set to true, it should use the default properties to "draw" the form for new records.
Hopefully, i haven't confused you by my poor wording.
Thanks.
 
I'm hoping that I don't have to write a function to set everything to visible again.

It is not a big deal to do:
Code:
Public Sub unhideAllCtrls()
  Dim ctrl As Access.Control
  For Each ctrl In Me.Controls
    ctrl.Visible = True
  Next ctrl
End Sub
call from the on current event
 
Hi Majp. thanks for response. the only problem i have is that there are a tonn of controls on the form.
But if this is the only way around it, i guess i have no choice.
 
oh.. and i guess i'd call this sub in the AfterUPdate event of the form?
 
I would think the on current event so that everytime you move to a new record the controls are unhidden then rehidden as necessary.

the only problem i have is that there are a tonn of controls on the form
My guess is a loop of a few hundred controls will take a few milliseconds, I would think you could live with that.

But if this is the only way around it, i guess i have no choice
I am sure that there is a more efficient way, but it seemed like you did not want to write a more code. I am not sure how you are calling your current code, but I would think that you may just need to call you current code on the on current event.

Without seeing your code it is hard to tell.
 
How are ya dotolee . . .

[blue]MajP[/blue] has presented [blue]ths shortest, fastest executing code that will do the job[/blue]. Getting specific will just slow the code down. Parsing thru 255 controls in not something your gonna feel.

[blue]Give it a shot just to see![/blue]

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

Be sure to see thread181-473997
Also faq181-2886
 

No one has mentioned the fact that you need to check to see whether the record is, in fact, new, so I'll do so now. The OnCurrent event will need to look something like this:

Code:
Private Sub Form_Current()
If Me.NewRecord Then
 unhideAllCtrls
Else
 If question1.value = 1 then
   'hide question2
    labelquestion2.visible=false
    question2.visible = false
    question2.value = NULL
 Else
   'do the opposite of the above
 End If 
End If
End Sub

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Guys, thank you very much for the help. I am definitely going to give it a try.
Thanks again MajP for your help.
And thanks TheAceMan!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top