Solved

Access form VBA - form fields - loop through

Posted on 2014-04-19
2
2,494 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 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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…

838 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