Solved

Access form VBA - form fields - loop through

Posted on 2014-04-19
2
2,543 Views
Last Modified: 2014-04-19
Hello All,

There are lets say 5 fields in a table. So i create a form from that table. Now I want vba to loop through all the fileds within that form and where >>
for each fld in userform1.controls

next fld

now if fld.name = "GG" then
1)change that field to a combobox and set its row source to be col1 from table 55
2) fld.name becomes cbo_This

please assist...

Thank you
0
Comment
Question by:Rayne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 40010890
place this codes in a regular module


Sub changeControlNames(frm As String)
Dim ctl As Control
DoCmd.OpenForm frm, acDesign, , , , acHidden
For Each ctl In Forms(frm).Controls
    If ctl.Name = "GG" Then
        ctl.ControlType = acComboBox
        ctl.RowSource = "select col1 from [table 55]"
        ctl.Name = "cbo_This"
    End If
Next
DoCmd.Close acForm, frm, acSaveYes
End Sub

Next
End Sub


to use

changeControlNames "NameOfForm"
0
 

Author Comment

by:Rayne
ID: 40010891
Thank you Rey, thank you :)
This works great!!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question