Bob G
Mar 30 2012, 08:38 AM
I in the process of trying to clean up a lot of code. I have a few sections that repeat within one form and also on another form. I am a little stumped on how to identify everything properly in a module.
I would have to list the controls involved as it isnt all of the text boxes involved.
if i can figure it out for one field I would know what to do with the rest.
I was thinking of using screen.activeform so i wouldnt have to know the name. Now, if there is a textbox on the form called txtslot1, i need something besides this.
screen.activeform.txtslot1.visible = false
everything i have tried so compiles ok but get an object required error when I use it
arnelgp
Mar 30 2012, 08:53 AM
screen.activeform.controls("txtslot1").visible = false
but you have to test if "txtslot1" is the active control with focus because you cannot hide control with focus on it.
if screen.activecontrol.name <> "txtslot1"
screen.activeform.controls("txtslot1").visible = false
end if
Bob G
Mar 30 2012, 09:08 AM
i was debating between trying it with the quotes around the controlname or posting the question.
Thanks for the assist.
pere_de_chipstick
Mar 30 2012, 10:42 AM
Hi Bob
One method I have used when using a function that is common to many forms or reports, is to pass the form or report identity in the argument of the function e.g.
CODE
Public Function fSomeFunction(srcFrm as Form)
srcFrm.SomeControlName = SomeVariable
End Function
And then calling the function from the form
CODE
fSomeFunction Me
hth
Bob G
Mar 30 2012, 10:47 AM
Hi Bernie,
Don't think that is what I am talking about here.
But thanks.
Bob
pere_de_chipstick
Mar 30 2012, 10:55 AM
Hi Bob
Sorry I've not understood your question then,
you talked about "I was thinking of using screen.activeform " and the example
srcFrm.txtslot1.visible = false
should work gven the form is passed in 'srcFrm As Form' as an argument to a function in module.
Could you expand a bit more?
Bob G
Mar 30 2012, 11:45 AM
i have a few forms that are kind of copies of each other. basically the first form has all the bells and whistles. the other forms have a few less items. example the first form would allow for an ADD but if you first did a find and the find form was now visible you would not be able to do an add. But, other fields would be exactly the same. name and everything. now, i have the same field.visible = true or field.visible = false on both of these forms. thought it might be good to move it to a module and then call the module thus removing some unnecessary lines of code. because each form has its own name, i was going to use screen.activeform which works fine. But I hadnt figured out how to tell it myfield without getting an object error. The answer was to enclose the name in quotes as earlier provided.
this works...
screen.activeform.controls("txtslot1").visible = false
EDIT:
this didnt work
screen.activeform.controls.txtslot1.visible = false
now i am working using this to make things a little neater. Hope this explains it better.
with screen.activeform
.controls()
end with
theDBguy
Mar 30 2012, 12:02 PM
Hi Bob,
Pardon me for jumping in...
QUOTE (Bob G @ Mar 30 2012, 09:45 AM)

this didnt work
screen.activeform.controls.txtslot1.visible = false
But this probably would have:
screen.activeform.controls
!txtslot1.visible = false
Just my 2 cents...
Bob G
Mar 30 2012, 12:04 PM
i will try that on the next similar piece with different controls.
as they say in Alaska... Mush....
pere_de_chipstick
Mar 30 2012, 12:12 PM
Hi Bob
Ah, I was thinking more about the screen.activeform issue as some developer's don't like using screen.... as you sometimes can't guarantee that the correct form retains the active status.
Still, DBg's suggestion should sort out your current issue, though I would argue that passing the form in the function argument was more robust when you could use:
CODE
with srcFrm
.Controls("ControlName") .....
end with
hth
Bob G
Mar 30 2012, 12:32 PM
as we are never surprised, the DBG was spot on yet again.
this is what the outcome is and works !
CODE
with screen.activeform.controls
!myfield.visible = true
end with
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.