Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

A weblog about Microsoft Access, SQL Azure, and SQL Server Tips and Code Samples
Browse by Tags · View All
Access Tips 45
Microsoft Access 45
VBA 41
database 33
Access 33
Code 32
Software development 31
Microsoft Access Software Development 26
Free Access Downloads 25
Software 25

Archive · View All
October 2010 4
September 2008 4
June 2009 4
January 2008 3
July 2009 3
June 2007 2
May 2009 2
March 2011 2
July 2010 2
August 2011 2

Patrick Wood's Blog

Instantly Name Microsoft Access Form Controls

Jul 7 2010 7:45AM by Patrick Wood   

Even though Access is the best rapid development tool for databases I have ever used, some things can be drudgery. Take form controls for example. Access names the controls on a form the same as the control source. This makes it easy to have errors. You may try to use the name of the control but Access reads it as the name of the field. To avoid errors like this we have to go through the controls on a form and rename them one at a time. This can really slow down development and it gets to be drudgery after a few forms. So to save myself some time I wrote the following procedure which renames the most used controls on a form in a flash.

The code works by looping through the various controls on a form and adding an appropriate prefix to the existing name. You can run the procedure from the Immediate window using the following code:

Call NameFormControls("frmMyFormName")

Below is the procedure that does all the work. All you need to do is add it to a Standard Module and call it using the name of your form.

Public Sub NameFormControls(strFormName As String)

    Dim frm As Form
    Dim ctl As Control
    Dim strCtlName As String
    Dim ctlLabel As Label

    ' Open the Form in Design View and make it invisible
    DoCmd.OpenForm strFormName, acDesign, , , , acHidden

    ' Instatiate the form
    Set frm = Forms(strFormName)

    ' Loop through all the controls on the Form
    For Each ctl In frm.Controls
        ' Name specific controls according to their type
        ' making sure the control has not already been named
        Select Case ctl.ControlType
            Case acTextBox
                If Left(ctl.Name, 3) <> "txt" Then
                    ctl.Name = "txt" & ctl.Name
                End If
            Case acComboBox
                If Left(ctl.Name, 3) <> "cbo" Then
                    ctl.Name = "cbo" & ctl.Name
                End If
            Case acListBox
                If Left(ctl.Name, 3) <> "lst" Then
                    ctl.Name = "lst" & ctl.Name
                End If
            Case acCheckBox
                If Left(ctl.Name, 3) <> "chk" Then
                    ctl.Name = "chk" & ctl.Name
                End If
            Case acLabel
                Set ctlLabel = ctl
                If Left(ctl.Name, 3) <> "lbl" Then
                    ctl.Name = "lbl" & ctlLabel.Caption
                End If
        End Select
    Next ctl

    ' Close and save the Form
    DoCmd.Close acForm, strFormName, acSaveYes

    ' Release Memory
    Set ctlLabel = Nothing
    Set ctl = Nothing
    Set frm = Nothing 

End Sub

This code even names the labels! You may want to change the caption or format a label in some situations and this makes it much easier to manage.

I hope this code can help you make your Access development work a little easier and faster.


Republished from Access Easy Tips [18 clicks].  Read the original version here [32134 clicks].

Patrick Wood
101 · 2% · 521
2
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"Instantly Name Microsoft Access Form Controls" rated 5 out of 5 by 2 readers
Instantly Name Microsoft Access Form Controls , 5.0 out of 5 based on 2 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]