473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How do you change the control source of a text box?

31
I have two forms, one with two command buttons, the other is a testing critera input form. Both cmd bottons open the same form. The first opens it to input test criteria, and is attached to a table. The other cmd button I want to open the same form, but I want it attached to a query to select the test criteria for a specific part which I will use is to test data from another table to pull out the good parts. I'm thinking I need to change the control source for several text boxes to display the proper test criteria from the query. Any ideas on how to do this.
Jan 20 '10 #1

✓ answered by TheSmileyCoder

This code will change the subform's source object (form) and then alter the recordsource.

I have used this code along with a treeview where a user can click on several nodes, representing different things. Based on what tag the node has, different forms will be opened.

The frm_Container is the name of the control holding the subform. This is just example code and you will have to modify it of course.


Expand|Select|Wrap|Line Numbers
  1. Select Case strTag
  2.                 Case "System"
  3.                     'Open the system Documents form
  4.                     If Not Me.frm_Container.SourceObject = "frm_System" Then Me.frm_Container.SourceObject = "frm_System"
  5.                     If Not Me.lbl_FormContainer.Caption = "System" Then Me.lbl_FormContainer.Caption = "System"
  6.                     'Set recordsource
  7.                     Me.frm_Container.Form.RecordSource = "SELECT tbl_EvalNodes.* " & _
  8.                                                     " FROM tbl_EvalNodes " & _
  9.                                                     " WHERE KEY_EvalNode=" & getKeyItem(node.Key)
  10. End Select
To change a single textbox to use another controlsource (I have not tested the implications of this or if it is possible at runtime)
Expand|Select|Wrap|Line Numbers
  1. me.tb_BidderID.ControlSource="[tx_Bidder]"
I think you will need to try it out, to see what happens when changing this at runtime. For instance, if user has allready entered a value in textbox, and you change the controlsource, what then?

7 4662
Delerna
1,134 Expert 1GB
the general syntax for changing control properties on another form is
Expand|Select|Wrap|Line Numbers
  1. Forms!FormName.ControlName.Property=value
  2.  
Jan 21 '10 #2
If I've understood your question correctly, do you want to change the "record source" of a form? Or do you only want to change the "control source" of the text box.
However, I will provide you with both solutions...
To change the "Record Source" of a form.

Here's some code...

Assuming you have a command button on the form called "cmdTestCriteria".
On the cllick event of "cmdTestCriteria".


Private Sub cmdTestCriteria_Click()

Dim dbs As DAO.Database
Dim rs As DAO.Recordset
Dim frmTheSameForm As TheSameForm

Set dbs = CurrentDb()
Set rs = Me.RecordsetClone or Me.Recordset

DoCmd.OpenForm "frmTheSameForm"
TheSameForm.Recordset = "qryTestCriteria"
End Sub

If you want to change the "ControlSource" of one or several textboxes, then add as many tables and table fields to the query as needed.


Best Regards,

Lamar Dixon, Jr.
President
Sallient Technologies, LLC
MobileMessageMedia(MCubed)
Jan 21 '10 #3
tomric
31
Yes, I want to change the record source. I've tried the code and I keep comming up with a compile error, user-defined type not defined, on the statement Dim frmTestingcriteria as Testingcriteria. The form does exist and that's the name of it, any sugestions as to why this is occuring?
Jan 21 '10 #4
Hello,
The statement "Dim frmTestingcriteria as Testingcriteria" is a euphemism.

The "Compile Error" you are getting is because the form does not exist. Hence the "User-Defined Type". You're not going to open a new form, you're changing the recordset for the EXISTING form.

So here's some code...

Private Sub cmdTestCriteria_Click()

Dim dbs As DAO.Database
Dim rs As DAO.Recordset


Set dbs = CurrentDb()
Set rs = Me.RecordsetClone or Me.Recordset

Me.Recordset = "qryTestCriteria"
End Sub
Jan 22 '10 #5
tomric
31
Will that allow to open a second form and change the record set of that form at the same time?
Jan 22 '10 #6
TheSmileyCoder
2,322 Expert Mod 2GB
This code will change the subform's source object (form) and then alter the recordsource.

I have used this code along with a treeview where a user can click on several nodes, representing different things. Based on what tag the node has, different forms will be opened.

The frm_Container is the name of the control holding the subform. This is just example code and you will have to modify it of course.


Expand|Select|Wrap|Line Numbers
  1. Select Case strTag
  2.                 Case "System"
  3.                     'Open the system Documents form
  4.                     If Not Me.frm_Container.SourceObject = "frm_System" Then Me.frm_Container.SourceObject = "frm_System"
  5.                     If Not Me.lbl_FormContainer.Caption = "System" Then Me.lbl_FormContainer.Caption = "System"
  6.                     'Set recordsource
  7.                     Me.frm_Container.Form.RecordSource = "SELECT tbl_EvalNodes.* " & _
  8.                                                     " FROM tbl_EvalNodes " & _
  9.                                                     " WHERE KEY_EvalNode=" & getKeyItem(node.Key)
  10. End Select
To change a single textbox to use another controlsource (I have not tested the implications of this or if it is possible at runtime)
Expand|Select|Wrap|Line Numbers
  1. me.tb_BidderID.ControlSource="[tx_Bidder]"
I think you will need to try it out, to see what happens when changing this at runtime. For instance, if user has allready entered a value in textbox, and you change the controlsource, what then?
Jan 22 '10 #7
tomric
31
Thank you very much, I got it to work.
Jan 26 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Billy Jacobs | last post by:
I have created a DataGridColumnDatePicker Component so that I can put a datetimepicker control in my datagrid. It almost works. When I put my mouse in the cell it changes to a datetimepicker...
13
by: nyt | last post by:
I have a problem of number and text field. I got the database file(mdb) that contains many combo boxes used and its list values are created by "value list" For eg field Field name= 'furniture'...
1
by: Mirek Endys | last post by:
Hi all, I thought, that this is an usual thing, but Im wrong. I have a DataList control and there is a Label control. I need to change the Text propertz of the Label control. How to do it....
0
by: nate | last post by:
the error returned is this: Server Error in '/AnnAccRpt' Application. -------------------------------------------------------------------------------- Could not find control 'DropDownList1' in...
2
by: Greg Strong | last post by:
Hello All, Is it possible to change table field lookup properties in code? I've been able to change other field properties in code, however so far no luck with field lookup properties. What...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
8
by: mlwerth | last post by:
Dear Access Group: This is the most basic and most embarrassing of questions, but I cannot find where to change the data type of a text field that I have in Access 2003 to a number field. I've...
5
by: agarwasa2008 | last post by:
Hi, I have a linked table called tbltest and some bounded forms (which add, update, delete records) that were created using that linked table. For some necessary reasons I had to create another...
15
beacon
by: beacon | last post by:
Hi everybody, Using Access 2003. I'm trying to dynamically set the record source for the current form and set the control source for a text box to input data to one of three tables. I have a...
6
by: AAaron123 | last post by:
I'm using the CreateUserWizard Web Server Control The error message when the passwords do not match is colored red. Red does not show well against my background so I like to change that color. I...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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...

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.