Solved

Access form VBA - form fields - loop through

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

919 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

14 Experts available now in Live!

Get 1:1 Help Now