Link to home
Start Free TrialLog in
Avatar of alfamikefoxtrot
alfamikefoxtrot

asked on

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.
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

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
Next
Next
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...
Avatar of alfamikefoxtrot
alfamikefoxtrot

ASKER

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?
I think the only way is the procedure i described...open the form (hidden) in design mode..make the changes...save the form....open it normally
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?
SOLUTION
Avatar of Anders Ebro (Microsoft MVP)
Anders Ebro (Microsoft MVP)
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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...! :)
What is the scenario you are trying to support by moving the control @ runtime?
Thanks for the help all. Closing question based on Dale's feedback.