MS Access -- locate control on tab page programmatically

Hi all -- anyone know an easy way to programmatically relocate a field on a form to a location on a tab page on the same form? I can MoveSize controls all over the place but this one eludes me. Likely some simple setting that I am completely overlooking.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

John TsioumprisSoftware & Systems EngineerCommented:
For locating try  this
Private Sub Command_Click()
For Each pg In Me.TabControl.Pages
For Each ctl In pg.Controls
    Debug.Print pg.Name & " -- " & ctl.Name
End Sub

Open in new window

If you want to change the controls of a page i guess you need to open the form 1st in design view ...manipulate the controls and then save it and reopen it...
alfamikefoxtrotAuthor Commented:
I probably didn't word the question title that effectively. Locating (e.g., finding) the control isn't a problem. What I need help with is in taking an existing control (like a field or a button) from one part of my form and moving it to a tabpage on the same form. I can execute other control moves during the form OnLoad event using Move -- however, if I use that while trying to move the control onto a page, the control ends up behind the page. I suspect that there is a way of referring to either the control or page so that I can specify not just the new location of the control but also what page I want to move it to, and do that during OnLoad as I do with the other moves I'm making. Does this help to clarify?
John TsioumprisSoftware & Systems EngineerCommented:
I think the only way is the procedure i the form (hidden) in design mode..make the the it normally
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

alfamikefoxtrotAuthor Commented:
So John -- I don't think any of the procedure you describe is debatable (other than the need to execute in design mode -- if I'm able to use the Move or MoveSize methods to move controls around at runtime, it doesn't make sense to me that this would be any different). My question is much more specific -- when you propose to make the changes, how would you refer programmatically to the page location? If I use Move or MoveSize, I'm providing instructions to the form to locate the control in question based on its anchoring information (top/left in this case) and a certain number of inches or twips down and to the right from the top-left corner of the form. The one variable would then be if I'm trying to locate a control onto a page also sitting on the form. It's not possible to convey this information numerically since if I have multiple pages, I can have any of several controls with the same coordinates described above with the only difference being a designation -- somewhere -- that identifies what page each control sits on. What I'm trying to do is to figure out what additional instruction to pass to the form that tells it, in addition to the cartesian location, that I want the control to live on page 2, for example. does that help to clarify further?
Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
I tried a few approaches, but couldn't get it to work while in form view. I tried to set the parent of the textbox (no success) while in code.
Why do you need to do it at runtime?

Another approach might be 2 simple use 2 textboxes. Note that both boxes can be bound to the same field.
Dale FyeOwner, Developing Solutions LLCCommented:

controls inside a tab page have a parent of the page


But this property is read only, so you cannot move a control onto a tab at runtime.  The only time I ever attempt to move a control on a form is when the form is resized, so I can see no utility in attempting to move a control from one tab to another or from a form to a tab on that form.

I would strongly recommend that you simply use multiple controls, with similar names.  This way, if you needed to, you could declare a new control varable, and sign the control to the control which exists on whichever tab you want to reference, something like:
Dim ctrl_txtSalesVol as textbox

if me.TabControl = 0 then 
    set ctrl_txtSalesVol = me.txt_SalesVol_page1
    set ctrl_txtSalesVol = me.txt_SalesVol_Page2
end if

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
adding on to what Anders wrote: rather than just having one place to show data, I often display it somewhere else and then name the control: myfieldname_echo (since I like to name bound controls for what they contain). If you do not want to allow editing in the location that is being echoed, you can set Locked to True for that one. If the control is echoed in more than one location, you might want to append a number to the name or a reference to the location.

... and now I see Dale also suggested multiple controls ... with similar names too. Dale's naming convention for bound controls is different than mine -- imo, it really doesn't matter all that much as long as you have a convention ... ie" logic behind the names in your application
alfamikefoxtrotAuthor Commented:
Thanks a bunch for the thoughts and options, y'all. The multiple item option may be the best suited to my solution. I have another similar option which may be a possibility too (basically dealing with setting the rowsource). Really interesting that the ability to place a control on a tab can only be done at design view (which does seem to make some sense, though). I'll mull this over and let you know how I went. Appreciate the help...! :)
Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
What is the scenario you are trying to support by moving the control @ runtime?
alfamikefoxtrotAuthor Commented:
Thanks for the help all. Closing question based on Dale's feedback.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.