473,386 Members | 1,706 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,386 software developers and data experts.

How to view a collection as a recordset

Seth Schrock
2,965 Expert 2GB
Is there a way to view all the items in a collection in a form? For example, lets say that I wanted to have a list of all the controls on a given form and be able to set properties for those controls through the use of a form. Do I just need to loop through the collection and add the names of the controls to a temp table and then find the control name through a variable when I need to get to its properties? I kind of think that I know how to do this, but I've never done it before.
May 29 '13 #1

✓ answered by Oralloy

Seth,

The quick way of converting is to simply create a temporary table and insert every value of the collection into the table.

Of course, if I am reading what you are writing correctly, it seems that your intent is to have a list of existing controls, with a one-to-many relationship to the attributes for each of the controls. Perhaps it is best not to bother with a temporary table; instead, have two perminant tables with the associated forms already in the database - then when you want to edit properties for a specific control(s), simply insert the information into the existing tables.

What do you think?

Regards,
Oralloy

6 4322
ADezii
8,834 Expert 8TB
Seth, I am a little confused as to the exact nature of your question, but I will give it a shot. The following Code will:
  1. Loop through all Controls on a Form.
  2. Filter out only Command Buttons.
  3. Dynamically adjust their Widths based on a Scale Factor contained within a Text Box on a Form.
Expand|Select|Wrap|Line Numbers
  1. Dim ctl As Control
  2. Dim sngScaleFactor As Single
  3.  
  4. If IsNull(Me![txtScale]) Then Exit Sub
  5.  
  6. sngScaleFactor = Me![txtScale]
  7.  
  8. 'Need to set some Ranges on the Scale Value and if they are out of
  9. 'a specified Range, maintain the existing Width
  10. If sngScaleFactor < 0.25 Or sngScaleFactor > 2 Then
  11.   sngScaleFactor = 1        'Maintain existing Width
  12. End If
  13.  
  14. For Each ctl In Me.Controls
  15.   If ctl.ControlType = acCommandButton Then
  16.     ctl.Width = ctl.Width * sngScaleFactor
  17.   End If
  18. Next
You can also manipulate a Control's Properties using a Variable referencing the Control:
Expand|Select|Wrap|Line Numbers
  1. Dim strControlName As String
  2.  
  3. strControlName = "cmdSearch"
  4.  
  5. 'Increase Control's Width by 50%
  6. Me.Controls(strControlName).Width = Me.Controls(strControlName).Width * 1.5
Am I even close? (LOL).
May 29 '13 #2
Seth Schrock
2,965 Expert 2GB
You are sort of close :) What sparked this question is in learning SQL Server, I have learned that it has default system views that lets you query all kinds of information that is similar to information that Access has in collections. For example, I could run a query to find all the table names or the fields in a given table. Because I can query this, I can view this information in a form (continuous or datasheet). I looked at the system tables for Access and I can't find any information like a list of controls for a given form. So I was wondering if I could somehow convert a collection (such as Me.Controls) to recordset so that I can then view the data that is in the collection in a form and have a field that would allow me to change the tag property for instance. This would allow my users (who I have set as administrators) to edit some properties without having to touch VBA.

I hope this makes it clearer.
May 29 '13 #3
Oralloy
988 Expert 512MB
Seth,

The quick way of converting is to simply create a temporary table and insert every value of the collection into the table.

Of course, if I am reading what you are writing correctly, it seems that your intent is to have a list of existing controls, with a one-to-many relationship to the attributes for each of the controls. Perhaps it is best not to bother with a temporary table; instead, have two perminant tables with the associated forms already in the database - then when you want to edit properties for a specific control(s), simply insert the information into the existing tables.

What do you think?

Regards,
Oralloy
May 29 '13 #4
Seth Schrock
2,965 Expert 2GB
Okay. So it sounds looping through the collection and writing the names to a table is the way to go. I think that I can do that.

Thanks Oralloy.
May 29 '13 #5
ADezii
8,834 Expert 8TB
You can write Code that will will populate a Table with the Names of all Forms as well as all the Controls associated with those Forms.
May 29 '13 #6
Seth Schrock
2,965 Expert 2GB
That is what I plan on doing.
May 29 '13 #7

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

Similar topics

4
by: sci | last post by:
Could someone help me by answering the questions below? What's a cursor? What's difference between Query and View? Is a RecordSet just part of a table? Can it be part of a query of view? If...
5
by: !TG | last post by:
I currently use Do while loop, but I'd rather use a For Loop though I have never gotten the hang of them. Would some one please be so kind as to show me how to loop through a recordset.
12
by: Neil | last post by:
I previously posted re. this, but thought I'd try again with a summary of facts. I have an Access 2000 MDB with a SQL Server 7 back end. There is a view that is linked to the database via ODBC...
3
by: Mika | last post by:
Is it possible to perform functions on a recordset (rather than on the source database), e.g. COUNT, MAX etc The reason I would like to do this is because I have a hugely complex view which...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
1
by: ano1optimist | last post by:
Has anyone had success with using a command collection with parameters to run a stored procedure from sql server? I'm frustrated and have been spending way too much time trying to make this work. ...
4
by: Lyn | last post by:
Hi, This question may seem a bit academic... To learn more about Access VBA, I have been enumerating the properties of various form controls. This was mostly successful and I have learned a lot...
36
by: kjvt | last post by:
Based on a prior posting, I've written a function to convert a recordset to a dataview. The first call to the function for a given recordset works perfectly, but the second call always returns a...
0
by: Rene Aichinger | last post by:
Hi, I've created a server control (it inherits from WebControl) wich has a property of genertic collection type. The type of the generic collection is NavigationItem, a little class I've...
1
by: Ed | last post by:
hi everyone, maybe someone can give me a hand here. I am working with vb 2005 and i have a gridview that i am loading data from a recordset. I have the recordset returned from the query and i am...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.