Solved

Access form VBA - form fields - loop through

Posted on 2014-04-19
2
2,438 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
2 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
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
Comment Utility
Thank you Rey, thank you :)
This works great!!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now