Rename forms into external DB

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

javiernews via AccessMonster.com

Hi,
I'm using this code but it does Not work for all forms. I have to repeat the
process several times to success.

Const cPrefixForm As String = "frm"
Dim accAppNew As New Access.Application
Dim obj As Object
Dim strObjCurr As String
Dim strObjNew As String

accAppNew.OpenCurrentDatabase "C:\My Documents\Customers.mdb", True
accAppNew.Visible = False

For Each obj In accAppNew.CurrentProject.AllForms

strObjCurr = obj.Name

If Left$(strObjCurr, Len(cPrefixForm)) <> cPrefixForm Then
strObjNew = cPrefixForm & strObjCurr
accAppNew.DoCmd.Rename strObjNew, acForm, strObjCurr
End If

Next obj

What am I doing wrong ???

Thank you
 
J

javiernews via AccessMonster.com

Thank you Alex for answering.

I tryed like this:

Const cPrefixForm As String = "frm"
Const cContainerForm As String = "Forms"
Dim obj As Object
Dim dbs As DAO.Database
Dim cnt As DAO.Container
Dim strNomObjCurr As String
Dim strNomObjNuevo As String
Dim intX As Integer




Set obj = CreateObject("Access.Application")
obj.OpenCurrentDatabase "C:\My Documents\Customers.mdb", True
obj.Visible = False


Set dbs = obj.CurrentDb
Set cnt = dbs.Containers(cContainerForm)


For intX = cnt.Documents.Count - 1 To 0 Step -1

strNomObjCurr = cnt.Documents(intX).Name

If Left$(strNomObjCurr, Len(cPrefixForm)) <> cPrefixForm Then
strNomObjNuevo = cPrefixForm & strNomObjCurr

obj.DoCmd.Rename strNomObjNuevo, acForm, strNomObjCurr

strNomObjCurr = strNomObjNuevo
End If

Next intX



But now the situation is little better, but the problem is always missing 1
form to be renamed.
Any help ?
 
J

javiernews via AccessMonster.com

Sorry the above code is Not working at all !
it stop at this point

obj.DoCmd.Rename strNomObjNuevo, acForm, strNomObjCurr '<<< HERE

What is wrong ?
any help ?
 
A

Alex Dybenko

Hi,
what if you do like this (air code):

redim aForms(accAppNew.CurrentProject.AllForms.count-1)
dim I as long

For Each obj In accAppNew.CurrentProject.AllForms
aFoms(I)= obj.Name
I=I+1
Next obj

for I=lbound( aForms()) to ubound( aForms())
If Left$(aFoms(I) , Len(cPrefixForm)) <> cPrefixForm Then
strObjNew = cPrefixForm & aFoms(I)
accAppNew.DoCmd.Rename strObjNew, acForm, aFoms(I)
End If
Next i

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com
 
J

javiernews via AccessMonster.com

Thank you Alex so much for you support

before your post I tried like this and is working goo too, (but is
unnecessary to loop twice)

accAppNew2.OpenCurrentDatabase strRuta, True, strPass
accAppNew2.Visible = False



For Each obj1 In accAppNew2.CurrentProject.AllForms
For Each obj2 In accAppNew2.CurrentProject.AllForms

strObjCurr = obj2.Name

If Left$(strObjCurr, Len(cPrefixForm)) <> cPrefixForm
Then
strObjNew = cPrefixForm & strObjCurr
strObjNew = funNormalizar(strObjNew)
accAppNew2.DoCmd.Rename strObjNew, acForm,
strObjCurr
End If

Next obj2
Next obj1

But I think you code is much better so I will change it
(After few changes your code is finally is like this:)

ReDim aForms(accAppNew2.CurrentProject.AllForms.Count - 1)
Dim I As Long

For Each obj In accAppNew2.CurrentProject.AllForms
aForms(I) = obj.Name
I = I + 1
Next obj

For I = LBound(aForms()) To UBound(aForms())
If Left$(aForms(I), Len(cPrefixForm)) <> cPrefixForm Then
strObjNew = cPrefixForm & aForms(I)
accAppNew2.DoCmd.Rename strObjNew, acForm, aForms(I)
End If
Next I

Thank you again you help me a lot today !!!
 

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