?
Solved

Access form VBA - form fields - loop through

Posted on 2014-04-19
2
Medium Priority
?
2,581 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

771 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