PC Review


Reply
Thread Tools Rate Thread

Code to rename tables

 
 
LisaB
Guest
Posts: n/a
 
      14th Jun 2004
I have just imported 50 tables from SQL to Access and they all have the dbo
name in front of the table name

dbo_tblCustomers

I would like to know if there is VBA code to go through the table and drop
the "dbo_ " that appears before each tables name.


Thank you


 
Reply With Quote
 
 
 
 
Gerald Stanley
Guest
Posts: n/a
 
      14th Jun 2004
Try something along the lines of
Dim tbl As DAO.tabledef

For Each tbl In TableDefs
If Left$(tbl.Name, 4) = "dbo_" Then
tbl.Name = Mid$(tbl.Name, 5)
End If
Next

Hope This Helps
Gerald Stanley MCSD
>-----Original Message-----
>I have just imported 50 tables from SQL to Access and they

all have the dbo
>name in front of the table name
>
>dbo_tblCustomers
>
>I would like to know if there is VBA code to go through

the table and drop
>the "dbo_ " that appears before each tables name.
>
>
>Thank you
>
>
>.
>

 
Reply With Quote
 
Chris Nebinger
Guest
Posts: n/a
 
      14th Jun 2004
I thought the Name property was read-only. I had to try
this to verify it.....


I always used the DoCmd.Rename method to rename objects...

I did find that QueryDef.Name is also read/write, but
dbs.Containers("Forms").Documents("Form1").Name is Read
Only....

I guess you learn something every day.


Chris Nebinger


>-----Original Message-----
>Try something along the lines of
>Dim tbl As DAO.tabledef
>
>For Each tbl In TableDefs
> If Left$(tbl.Name, 4) = "dbo_" Then
> tbl.Name = Mid$(tbl.Name, 5)
> End If
>Next
>
>Hope This Helps
>Gerald Stanley MCSD
>>-----Original Message-----
>>I have just imported 50 tables from SQL to Access and

they
>all have the dbo
>>name in front of the table name
>>
>>dbo_tblCustomers
>>
>>I would like to know if there is VBA code to go through

>the table and drop
>>the "dbo_ " that appears before each tables name.
>>
>>
>>Thank you
>>
>>
>>.
>>

>.
>

 
Reply With Quote
 
LisaB
Guest
Posts: n/a
 
      14th Jun 2004
I get a runtime error 424 Object required

Dim tbl As TableDef
Dim TD As TableDefs

For Each tbl In TD ****(Error - code stops Here)*****
If Left$(tbl.Name, 4) = "dbo_" Then
tbl.Name = Mid$(tbl.Name, 5)
End If
Next

"Gerald Stanley" <(E-Mail Removed)-> wrote in message
news:1c52a01c45223$fdfa2a60$(E-Mail Removed)...
> Try something along the lines of
> Dim tbl As DAO.tabledef
>
> For Each tbl In TableDefs
> If Left$(tbl.Name, 4) = "dbo_" Then
> tbl.Name = Mid$(tbl.Name, 5)
> End If
> Next
>
> Hope This Helps
> Gerald Stanley MCSD
> >-----Original Message-----
> >I have just imported 50 tables from SQL to Access and they

> all have the dbo
> >name in front of the table name
> >
> >dbo_tblCustomers
> >
> >I would like to know if there is VBA code to go through

> the table and drop
> >the "dbo_ " that appears before each tables name.
> >
> >
> >Thank you
> >
> >
> >.
> >



 
Reply With Quote
 
Gerald Stanley
Guest
Posts: n/a
 
      14th Jun 2004
Try

For Each tbl In CurrentDb.TD

Hope This Helps
Gerald Stanley MCSD
>-----Original Message-----
>I get a runtime error 424 Object required
>
>Dim tbl As TableDef
>Dim TD As TableDefs
>
>For Each tbl In TD ****(Error - code stops Here)*****
> If Left$(tbl.Name, 4) = "dbo_" Then
> tbl.Name = Mid$(tbl.Name, 5)
> End If
>Next
>
>"Gerald Stanley" <(E-Mail Removed)-> wrote

in message
>news:1c52a01c45223$fdfa2a60$(E-Mail Removed)...
>> Try something along the lines of
>> Dim tbl As DAO.tabledef
>>
>> For Each tbl In TableDefs
>> If Left$(tbl.Name, 4) = "dbo_" Then
>> tbl.Name = Mid$(tbl.Name, 5)
>> End If
>> Next
>>
>> Hope This Helps
>> Gerald Stanley MCSD
>> >-----Original Message-----
>> >I have just imported 50 tables from SQL to Access and they

>> all have the dbo
>> >name in front of the table name
>> >
>> >dbo_tblCustomers
>> >
>> >I would like to know if there is VBA code to go through

>> the table and drop
>> >the "dbo_ " that appears before each tables name.
>> >
>> >
>> >Thank you
>> >
>> >
>> >.
>> >

>
>
>.
>

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      14th Jun 2004
Actually, you don't need the TD object, but you want to instantiate a
reference to the Database:

Dim db As DAO.Database
Dim tbl As DAO.TableDef

Set db = CurrentDb()
For Each tbl In db.TableDefs
If Left$(tbl.Name, 4) = "dbo_" Then
tbl.Name = Mid$(tbl.Name, 5)
End If
Next tbl


For Each tbl In CurrentDb().TableDefs

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Gerald Stanley" <(E-Mail Removed)-> wrote in message
news:1c1f901c45251$9fb64e10$(E-Mail Removed)...
> Try
>
> For Each tbl In CurrentDb.TD
>
> Hope This Helps
> Gerald Stanley MCSD
> >-----Original Message-----
> >I get a runtime error 424 Object required
> >
> >Dim tbl As TableDef
> >Dim TD As TableDefs
> >
> >For Each tbl In TD ****(Error - code stops Here)*****
> > If Left$(tbl.Name, 4) = "dbo_" Then
> > tbl.Name = Mid$(tbl.Name, 5)
> > End If
> >Next
> >
> >"Gerald Stanley" <(E-Mail Removed)-> wrote

> in message
> >news:1c52a01c45223$fdfa2a60$(E-Mail Removed)...
> >> Try something along the lines of
> >> Dim tbl As DAO.tabledef
> >>
> >> For Each tbl In TableDefs
> >> If Left$(tbl.Name, 4) = "dbo_" Then
> >> tbl.Name = Mid$(tbl.Name, 5)
> >> End If
> >> Next
> >>
> >> Hope This Helps
> >> Gerald Stanley MCSD
> >> >-----Original Message-----
> >> >I have just imported 50 tables from SQL to Access and they
> >> all have the dbo
> >> >name in front of the table name
> >> >
> >> >dbo_tblCustomers
> >> >
> >> >I would like to know if there is VBA code to go through
> >> the table and drop
> >> >the "dbo_ " that appears before each tables name.
> >> >
> >> >
> >> >Thank you
> >> >
> >> >
> >> >.
> >> >

> >
> >
> >.
> >



 
Reply With Quote
 
Paul Johnson
Guest
Posts: n/a
 
      15th Jun 2004
Your runtime error is because your code doesn't set the object variables to
anything.

Need:
Set TD=CurrentDb.TableDefs
Then the For Each loop should be able to return the tabledefs.

Paul Johnson

"LisaB" <lbagley(ReTHis)@mayatech.com> wrote in message
news:u$(E-Mail Removed)...
> I get a runtime error 424 Object required
>
> Dim tbl As TableDef
> Dim TD As TableDefs
>
> For Each tbl In TD ****(Error - code stops Here)*****
> If Left$(tbl.Name, 4) = "dbo_" Then
> tbl.Name = Mid$(tbl.Name, 5)
> End If
> Next
>
> "Gerald Stanley" <(E-Mail Removed)-> wrote in message
> news:1c52a01c45223$fdfa2a60$(E-Mail Removed)...
> > Try something along the lines of
> > Dim tbl As DAO.tabledef
> >
> > For Each tbl In TableDefs
> > If Left$(tbl.Name, 4) = "dbo_" Then
> > tbl.Name = Mid$(tbl.Name, 5)
> > End If
> > Next
> >
> > Hope This Helps
> > Gerald Stanley MCSD
> > >-----Original Message-----
> > >I have just imported 50 tables from SQL to Access and they

> > all have the dbo
> > >name in front of the table name
> > >
> > >dbo_tblCustomers
> > >
> > >I would like to know if there is VBA code to go through

> > the table and drop
> > >the "dbo_ " that appears before each tables name.
> > >
> > >
> > >Thank you
> > >
> > >
> > >.
> > >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rename linked tables =?Utf-8?B?Q2xpZmY=?= Microsoft Access Macros 1 7th Apr 2005 02:36 AM
Rename tables + db size Benn Vosloo Microsoft Access 5 27th Feb 2004 06:41 AM
rename tables Joseph Smith Microsoft Access Macros 2 18th Dec 2003 11:40 AM
Re: Rename tables and fields Brendan Reynolds \(MVP\) Microsoft Access 0 18th Aug 2003 09:25 PM
Rename Tables Chris Wagner Microsoft Access Reports 1 15th Jul 2003 12:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:20 AM.