SBC News Groups wrote:
I have a form called frmMain. I have three blank controls on the form. I
want to assign the names from the table to the controls on the form, ex.
ctlfive displays two's data, and so on. Does that make sense to anyone?
I want to do this with VBA. The reason is that I will have other tables and
I want to use as few forms as possible so I setup up a form with many
controls and I turn off the ones that I do not need.
From a development point of view, it's probably a more cost effective
use of your time to simply copy the form and save it under a different
name, change the recordsource table and controlsources of the text
boxes/form controls.
The question that comes to my mind is are you sure you've designed your
data structure properly? The first thing that pops up with a red flag
is it sounds as if the different tables might actually all be the
same... Do not have tables with the same structure and types of data.
It's a stupid butthead like method of doing things.
Otherwise, I would use openargs on the form to populate stuff. The
following is air code.
Given tables tbl_stuff, tbl_other_stuff, tbl_things, all with different
fields and frmMain with UNBOUND text boxes txtA, txtB, txtC
Have a calling form with three buttons:
btnStuff with Caption "Data Enter Stuff" and on click event:
docmd.OpenForm "frmMain",,,,,,"Stuff"
btnOtherStuff with Caption "Data Enter Other Stuff" and on click event:
docmd.OpenForm "frmMain",,,,,,"OtherStuff"
btnThings with Caption "Data Enter Things" and on click event:
docmd.OpenForm "frmMain",,,,,,"Things"
frmMain would need code similar to the following for the on open event.
Option Compare Database
Option Explicit
Private Sub Form_Open(Cancel As Integer)
select case me.openargs
Case "Stuff"
me.recordsource = "tbl_Stuff" 'the name of the table
me.txtA.controlsource = "=Two"
me.txtB.controlsource = "=Three"
me.txtC.controlsource = "=Four"
Case "OtherStuff"
me.recordsource = "tbl_Other_Stuff" 'the name of the table
me.txtA.controlsource = "=Two"
me.txtB.controlsource = "=Three"
me.txtC.controlsource = "=Four"
Case "Things"
me.recordsource = "tbl_Things" 'the name of the table
me.txtA.controlsource = "=Two"
me.txtB.controlsource = "=Three"
me.txtC.controlsource = "=Four"
end select
end sub
Again, IF YOU HAVE MULTIPLE TABLES WITH THE SAME INFORMATION IN THE
FIELDS, YOUR DATA DESIGN IS SHAGGED UP, PERIOD.
--
Tim
http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me