How to rename Modules ?

  • Thread starter javiernews via AccessMonster.com
  • Start date
J

javiernews via AccessMonster.com

Hi

I'm using the following code to rename all Modules, the code is working good,
but I have
but I have to execute several times to change (re-name) all modules names.

How to re-name all modules clicking 1 time only ?

Private Sub Command0_Click()
On Error Resume Next

Const cPrefix As String = "mod_"
Dim obj As AccessObject
Dim dbs As Object
Dim strNewModule As String
Dim lngi As Long
Dim lngLong As Byte


Set dbs = Application.CurrentProject
lngi = 11


lngLong = Len(cPrefix)


For Each obj In dbs.AllModules

If left(obj.Name, lngLong) <> cPrefix Then
Start_2:
strNewModule = cPrefix & lngi
lngi = lngi + 1

If funExisteModulo(strNewModule) = False Then
DoCmd.Rename strNewModule, acModule, obj.Name '<< Old
Module name
Else
GoTo Start_2
End If
End If
Next obj


Set dbs = Nothing
Set obj = Nothing

MsgBox "The end"

End Sub





Private Function funExisteModulo(Module_Name As String) As Boolean

Dim obj As AccessObject
Dim dbs As Object

funExisteModulo = False
Set dbs = Application.CurrentProject
For Each obj In dbs.AllModules
If obj.Name = Module_Name Then
funExisteModulo = True
Exit For
End If
Next obj

Close_Function:
Set dbs = Nothing
Set obj = Nothing

End Function


Bye & thank you in advance
 
J

John Spencer

Try changing the code so you loop through in reverse order of the objects.

For ICount = Dbs.AllModules.Count -1 to 0
set Obj = DbsAllModules.Obj(iCount)

.... process here ---

Next ICount
 
J

javiernews via AccessMonster.com

Thanks John but is Not working,
even now is Not re-namimg any Module.

bye & thank you !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top