473,506 Members | 14,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Forms and Control Question

Can someone please tell/show me how I would do the following...

I have a table called tblOne. In tblOne I have three fields, two, three,
four.

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.

The ones I do need, I need to assign to the table columns.

Thanks for any help on this...

Mike
m charney at sbc global dot net
Jan 15 '07 #1
8 1343
I guess you could do this through setting the record source of the form
and the control sources of the controls, although it is probably not
example of good coding.

E.g.
frmMain.RecordSource = "tblOne"
frmMain.ctlFive = "fldTwo"
....

Jan 15 '07 #2
I can do that but with 24 fieds on tne form it can be a lot of programming.

I was wondering if there was a way to loop through and have them assign that
way. Lots less programming lines.

Mike

"Mike" <mi*************@hotmail.comwrote in message
news:11*********************@q2g2000cwa.googlegrou ps.com...
>I guess you could do this through setting the record source of the form
and the control sources of the controls, although it is probably not
example of good coding.

E.g.
frmMain.RecordSource = "tblOne"
frmMain.ctlFive = "fldTwo"
...

Jan 15 '07 #3
What you could do is store the information in some kind of master table
and then loop through the information and assign the field-values to
the corresponding controls.

Jan 15 '07 #4
That would be duplicating information that is already in teh DB.

I know there has to be a way to do this, I just can't seem to figure it out.

Thanks anyway.

Mike

"Mike" <mi*************@hotmail.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
What you could do is store the information in some kind of master table
and then loop through the information and assign the field-values to
the corresponding controls.

Jan 15 '07 #5
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
Jan 15 '07 #6
Hi Tim,

No I have different tables and they do not have the same information in
them. One is customer data, one is clerk data, one is consignor data. I
wanted to use the same form and just reassign the controls based on the
records source.

Me.RecordSource = "tblCustomers"

I started to program that code the way you have it but it gets really long
with 24 different text/lable controls, buttons and other misc things. I have
to change the TOP, LEFT, WIDTH on each control.

I wanted to make just one form, but I guess it is looking like I might not
be able to do that.

Thanks,

Mike.

"Tim Marshall" <TI****@PurplePandaChasers.Moertheriumwrote in message
news:eo**********@coranto.ucs.mun.ca...
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

Jan 15 '07 #7
SBC News Groups wrote:
I started to program that code the way you have it but it gets really long
with 24 different text/lable controls, buttons and other misc things. I have
to change the TOP, LEFT, WIDTH on each control.

I wanted to make just one form, but I guess it is looking like I might not
be able to do that.
If you're going to need to change widths and other appearance
characteristics, it's really much easier to go with different forms,
IMO. 8)
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me
Jan 15 '07 #8

"SBC News Groups" <me@you.netwrote
No I have different tables and they do not have the same information in
them. One is customer data, one is clerk data, one is consignor data. I
wanted to use the same form and just reassign the controls based on the
records source.

Me.RecordSource = "tblCustomers"
What you want to do can be done, but it does not allow you to use the
appropriate kind of Controls for different types of data, so if your Fields
are not all text Fields with individually entered text, it is unlikely to be
user-friendly. And, if they are, it will still be, at best, difficult to
adjust the size of the displayed Controls to the underlying data... unlike
Reports, the "CanGrow" and "CanShrink" properties you see on Controls on
Forms do not work.

But, since this is "only" a matter of usability, rather than a matter of
design that will eventually "rise up to bite you in the tender places", the
following VBA code does what you want for a form with six Labels and six
Text Boxes... for Tables with fewer Fields, the remaining Labels are blank
and the remaining Text Boxes empty. If I were doing this for real, live
users, I'd certainly at least make any unused text boxes invisible.

But, before you get excited about a method that works, let me repeat, your
users will not thank you for using such a method for your own convenience --
and I suspect, in time, that will be true even if you are the only user.

The name of the underlying Table or Query is passed as a text string in the
OpenArgs argument of a DoCmd.OpenForm, and the following event code in the
"General Form" works for me. You'll need to add your own error handling,
etc.:

Private Sub Form_Open(Cancel As Integer)
Me.RecordSource = Me.OpenArgs
End Sub

Private Sub Form_Load()
Dim rs As DAO.Recordset
Dim i As Integer, intMax As Integer
Set rs = Me.RecordsetClone
intMax = IIf((rs.Fields.Count - 1) 5, 5, rs.Fields.Count - 1)
For i = 0 To intMax
Me("Label" & Format((i + 1), "#0")).Caption = rs.Fields(i).Name
Me("TextBox" & Format((i + 1), "#0")).ControlSource =
rs.Fields(i).Name
Next i
rs.Close
Set rs = Nothing
End Sub

and, you could do the Form_Load code in fewer lines by using
Me.RecordsetClone directly, but this seemed more readable to me.

Larry Linson
Microsoft Access MVP
Jan 15 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2409
by: Soryt | last post by:
Hi everyone ! 1) An example from help: "Each Form object has a Controls collection, which contains all controls on the form. You can refer to a control on a form either by implicitly or...
4
2950
by: waltborders | last post by:
Hi, Because the blind are unable to use a mouse, keyboard navigation is key. A major difficulty is that not all windows forms controls are keyboard 'tab-able' or 'arrow-able' or have "tab...
1
1370
by: Sunil Sabir | last post by:
Dear All, I have 4 web ASP.net Forms. I use a image control to move between these forms.The problem I am facing is that I cannot preserve the state of the form when moving between different...
6
2854
by: William F. Zachmann | last post by:
We've got a project going that involves moving an old web site with a massive dll written in C++ that produces most of the output from a SQL 7.0 data base on NT4 onto IIS on Windows 2003 Server...
0
1443
by: fds | last post by:
Hello! I have a very specific question and that is about how to inherit a control for example the control System.Windows.Forms.TextBox without causing the environment to delete the control when...
0
1587
by: Tony Johansson | last post by:
Hello! I have a very specific question and that is about how to inherit a visual control for example the control System.Windows.Forms.TextBox without causing the environment to delete the...
4
1260
by: =?Utf-8?B?VGVycmFuY2U=?= | last post by:
I have a question about functionality I was wondering if anyone ever tried. Here is my problem/question. I'm currently in the motions of learning C# with that said I created a windows application...
14
3333
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using VS2005 and .net 2.0. I'm creating an application that has 3 forms. I want allow users to move forward and backward with the forms and retain the data users have entered. I thought...
5
1361
by: EManning | last post by:
Using A2K. I've got a request to develop a database consisting of survey questions. There are 2 sets of questions, set A and set B. A has 12 questions, B has 11. The requester of this database...
21
3287
by: Dan Tallent | last post by:
In my application I have a form (Customer) that I want to be able to open multiple copies at once. Within this form I have other forms that can be opened. Example: ZipCode. When the user enters...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.