My Assistant
![]() ![]() |
|
|
Mar 30 2012, 08:38 AM
Post
#1
|
|
|
UtterAccess VIP Posts: 8,191 From: CT |
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 |
|
|
|
Mar 30 2012, 08:53 AM
Post
#2
|
|
|
UtterAccess Ruler Posts: 1,090 |
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 |
|
|
|
Mar 30 2012, 09:08 AM
Post
#3
|
|
|
UtterAccess VIP Posts: 8,191 From: CT |
i was debating between trying it with the quotes around the controlname or posting the question.
Thanks for the assist. |
|
|
|
Mar 30 2012, 10:42 AM
Post
#4
|
|
|
UtterAccess VIP Posts: 7,646 From: South coast, England |
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 |
|
|
|
Mar 30 2012, 10:47 AM
Post
#5
|
|
|
UtterAccess VIP Posts: 8,191 From: CT |
Hi Bernie,
Don't think that is what I am talking about here. But thanks. Bob |
|
|
|
Mar 30 2012, 10:55 AM
Post
#6
|
|
|
UtterAccess VIP Posts: 7,646 From: South coast, England |
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? |
|
|
|
Mar 30 2012, 11:45 AM
Post
#7
|
|
|
UtterAccess VIP Posts: 8,191 From: CT |
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 |
|
|
|
Mar 30 2012, 12:02 PM
Post
#8
|
|
|
Access Wiki and Forums Moderator Posts: 48,595 From: SoCal, USA |
Hi Bob,
Pardon me for jumping in... this didnt work screen.activeform.controls.txtslot1.visible = false But this probably would have: screen.activeform.controls!txtslot1.visible = false Just my 2 cents... (IMG:style_emoticons/default/2cents.gif) |
|
|
|
Mar 30 2012, 12:04 PM
Post
#9
|
|
|
UtterAccess VIP Posts: 8,191 From: CT |
i will try that on the next similar piece with different controls.
as they say in Alaska... Mush.... |
|
|
|
Mar 30 2012, 12:12 PM
Post
#10
|
|
|
UtterAccess VIP Posts: 7,646 From: South coast, England |
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 |
|
|
|
Mar 30 2012, 12:32 PM
Post
#11
|
|
|
UtterAccess VIP Posts: 8,191 From: CT |
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 |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 18th June 2013 - 09:01 PM |