Results 1 to 7 of 7

Thread: Renaming forms

  1. #1
    Join Date
    Apr 2010
    Posts
    12

    Unanswered: Renaming forms

    Hi all! I have what would seem to be a problem with a fairly straightforward answer but I am having alot of difficulty solving it. Here it is:

    I used improper naming conventions when I named the forms in my database and now I'd like to rename them properly but I have no idea where to start this process. I rename the forms themselves, change their captions, and hunt for all references in my code and rename those as well but Access is still complaining about not being able to find the referenced forms.

    What is the best way to go about renaming forms in a database? Thanks!

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Highlight the form name, select rename, copy the name, search through your code and paste the name in all places needed. Somewhere you still have a reference to the old name or mis-spelling (ie. it could even be in the conditional formatting of a field which is often the culprit, or in the criteria of the recordsource query of a form/subform.)

    And of course, make sure your forms are named without spaces. A typical name might be: frmEditCustomers.
    Last edited by pkstormy; 04-27-10 at 21:43.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You should consider buying the "Renaming Wizard for Microsoft Access". It's cheap and performs very well: Microsoft Access Downloads - Add Ins, Wizards, VBA Code & Tools

    Otherwise you can write your own application for renaming objects. It consists in exploring every class of Access objects and examine several properties of each object, searching for the name you want to change. For VBA modules, you can rely on the built-in Search and Replace function. Here is a quick example (just a frame, actually) of what can be done:
    Code:
    Function SearchInForms(SearchedString As String)
    
        Dim obj As AccessObject
        Dim frm As Form
        Dim ctl As Control
        Dim pty As Property
        Dim strFormName As String
        
        On Error Resume Next   ' Some properties are not accessible in design view.
        For Each obj In CurrentProject.AllForms
            strFormName = obj.Name
            DoCmd.OpenForm obj.Name, acDesign
            Set frm = Forms(strFormName)
            For Each pty In frm.Properties
                If InStr(pty.Value, SearchedString) Then
                    If Err.Number = 0 Then
                        Debug.Print frm.Name
                        Debug.Print Tab(10); pty.Name, pty.Value
                    End If
                End If
                Err.Clear
            Next pty
            For Each ctl In frm.Controls
                For Each pty In ctl.Properties
                    If InStr(pty.Value, SearchedString) Then
                        If Err.Number = 0 Then
                            Debug.Print strFormName
                            Debug.Print Tab(10); ctl.Name
                            Debug.Print Tab(20); pty.Name, pty.Value
                        End If
                    End If
                    Err.Clear
                Next pty
            Next ctl
            Set frm = Nothing
            DoCmd.Close acForm, strFormName
        Next
    
    End Function
    Have a nice day!

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I once used a product called: FMS Analyzer which worked fairly well.

    Microsoft Access, SQL Server, Visual Studio .NET, and Visual Basic (VB6) Software Products, Consulting and Programming Services from FMS

    Although it did create some overhead within the mdb application that I didn't really like but again, it worked very well and produced some nice reports.

    Nice code Sinndho.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  5. #5
    Join Date
    Sep 2006
    Posts
    265
    Whilst may be able to rename the Forms all the calls to the Old Form Names will be no longer work.

    Firstly, if you are using VBA you can search the Project and do a Replace on DoCmd OpenForm FormName

    Secondly, using With CodeContextObject in VBA is not Form dependent and avoids explicit referencing to individual Forms.

    Simon

  6. #6
    Join Date
    Apr 2010
    Posts
    12
    Thanks for your help guys!

    Nick

  7. #7
    Join Date
    Oct 2012
    Posts
    5

    Lightbulb Renaming shortcuts instead of forms

    This is a postcript to this thread

    I was in a similar situation as intergnat1 using Access 2010.

    I renamed a form in the navigation pane, but the VBA which referenced the old name still worked.

    What I had not appreciated was that I was using custom groups and these actually contain shortcuts. I had simple renamed the shortcut and not the actual form.

    There is a useful Microsoft document "Manage database objects in the Navigation Pane" which states:

    "When you view custom categories and groups from the Navigation Pane, you always see the shortcuts to the objects. Shortcuts can be identified by a small arrow next to the lower-left corner of the object icon."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •